简体   繁体   English

Visual Basic中的自定义DataGridView列?

[英]Custom DataGridView Column In Visual Basic?

I'm trying to create a custom DataGridViewColumn and DataGridViewCell, and have found this article to be a great resource. 我试图创建一个自定义的DataGridViewColumn和的DataGridViewCell,并发现文章是一个很好的资源。 I'm done creating the DataGridViewColumn class and the DataGridViewCell class, however, when I try to edit the type of the column, my new custom classes don't show up as one of the options. 创建完DataGridViewColumn类和DataGridViewCell类后,但是,当我尝试编辑列的类型时,新的自定义类不会显示为选项之一。 My DataGridViewScheduleColumn inherits DataGridViewColumn, so I'm not too sure what I'm doing wrong. 我的DataGridViewScheduleColumn继承了DataGridViewColumn,所以我不太确定自己在做什么错。 Is there anything else I need to do to expose these classes to the IDE? 我还需要做些什么来将这些类公开给IDE?

Thanks. 谢谢。

Here is the custom column class 这是自定义列类

Public Class DataGridViewScheduleColumn
    Inherits DataGridViewColumn


Public Sub New()
    Me.CellTemplate = New DataGridViewScheduleCell
    Me.ReadOnly = True
End Sub

Public MaxValue As Long
Private needsRecalc As Boolean = True

Public Sub calcMaxValue()
    If needsRecalc Then
        Dim colIndex As Integer = Me.DisplayIndex
        For rowIndex As Integer = 0 To Me.DataGridView.Rows.Count - 1
            Dim row As DataGridViewRow = Me.DataGridView.Rows(rowIndex)
            MaxValue = Math.Max(MaxValue, CLng(row.Cells(colIndex).Value))

        Next
        needsRecalc = False
    End If
End Sub

End Class 末级

Is your custom DGV column and cell code in a different project than the Form you're trying to use them on? 您自定义的DGV列和单元格代码是否在与要使用它们的表单不同的项目中?

If so, you need to add a reference to your custom DGV column project from your Form project. 如果是这样,则需要从Form项目中添加对自定义DGV列项目的引用。 Do so by right clicking your Form project, select 'Add Reference...' from the context menu and add the DGV column project (or the project's output). 为此,右键单击您的Form项目,从上下文菜单中选择“添加引用...”,然后添加DGV列项目(或项目的输出)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM