首先感谢您的帮助。
这是关于 Componentone 的 True DBGrid,所以这可能不是期待答案的最佳地点,但在这一点上,我觉得我已经尽我所能,所以我愿意试一试。
在过去的几天里,我花了很多时间试图弄清楚如何在 True DBGrid 中创建自定义单元格,但目前我陷入了困境。我已经阅读了尽可能多的文档,并且所有关于 True DBGrid 的教程,但是我能得到的最远的都显示在下面的附图中。
在这里,如果您双击一个单元格,我可以在他们单击的单元格中显示一个自定义控件。但是,我希望单元格始终可见,而不仅仅是在单击它时,而且我希望它基于行本身,而不仅仅是 displayColumn,就像我现在正在重新加载“DisplayColumn.DataColumn.Editor”一样每次单击不同的单元格时。我的此性能代码如下所示。
' Retrieve Column
Dim objPrefDisplayColumn As C1.Win.C1TrueDBGrid.C1DisplayColumn = Me.TestGrid.Splits(0).DisplayColumns("ColumnFieldName")
'Retrieve data from database
Dim data As DataTable = ' My call to database table goes here Retrieve data that relates to row
' Create Custom Controller and Insert Data from table into it
Dim prvNewCellList As New TestCellList
prvNewCellList.LabelButtonHeight = Me.TestGrid.RowHeight / pref.Rows.Count
prvNewCellList.LabelWidth = (objPrefDisplayColumn.Width * 0.9)
prvNewCellList.ButtonWidth = (objPrefDisplayColumn.Width * 0.1)
prvNewCellList.Action_LoadUI(data)
' Assign Custom Controller to Column
objPrefDisplayColumn.DataColumn.Editor = prvNewCellList
objPrefDisplayColumn.Button = True
objPrefDisplayColumn.ButtonAlways = True
objPrefDisplayColumn.DropDownList = False
objPrefDisplayColumn.DataColumn.DropDown = Nothing
当我查看 DataGridView 的教程时,我知道这应该是可能的,如下面的链接,它们放置在自定义的“DataGridViewTextBoxCell”中,如图所示。
根据我阅读的有关 TrueDBGrid 的内容,以及 ComponentOne 最有可能使用 DataGridView 作为创建 TrueDBGrid 的模板的预期逻辑,我预计创建自定义单元格的方式会非常相似。但是,在尝试使用 TrueDBGrid 重新创建此示例后,如下所示,我发现列不接受“DataGridViewColumn”,当我尝试将其更改为“C1DataColumn”以满足其期望时,我发现该类与字段没有任何相似之处“ CellTemplate”,可用于创建自定义单元格。在这一点上,我几乎已经准备好相信自定义单元的功能在 TrueDBGrid 的开发过程中被遗忘了,但是,我已经准备好被证明是错误的。
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Dim col As New DataGridViewRolloverCellColumn()
Me.TestGrid.Columns.Add(col)
Catch ex As Exception
MsgBox("error arrose", vbInformation, "error")
End Try
End Sub
End Class
Public Class DataGridViewRolloverCellColumn
Inherits DataGridViewColumn
Public Sub New()
Me.CellTemplate = New DataGridViewRolloverCell()
End Sub
End Class
Public Class DataGridViewRolloverCell
Inherits DataGridViewTextBoxCell
Protected Overrides Sub Paint( _
ByVal graphics As Graphics, _
ByVal clipBounds As Rectangle, _
ByVal cellBounds As Rectangle, _
ByVal rowIndex As Integer, _
ByVal elementState As DataGridViewElementStates, _
ByVal value As Object, _
ByVal formattedValue As Object, _
ByVal errorText As String, _
ByVal cellStyle As DataGridViewCellStyle, _
ByVal advancedBorderStyle As DataGridViewAdvancedBorderStyle, _
ByVal paintParts As DataGridViewPaintParts)
' Call the base class method to paint the default cell appearance.
MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, _
value, formattedValue, errorText, cellStyle, _
advancedBorderStyle, paintParts)
' Retrieve the client location of the mouse pointer.
Dim cursorPosition As Point = _
Me.DataGridView.PointToClient(Cursor.Position)
' If the mouse pointer is over the current cell, draw a custom border.
If cellBounds.Contains(cursorPosition) Then
Dim newRect As New Rectangle(cellBounds.X + 1, _
cellBounds.Y + 1, cellBounds.Width - 4, _
cellBounds.Height - 4)
graphics.DrawRectangle(Pens.Red, newRect)
End If
End Sub
End Class
再次感谢您的帮助