【问题标题】:How to check the type of a DataGridView Cell?如何检查 DataGridView 单元格的类型?
【发布时间】:2014-01-08 07:45:31
【问题描述】:

我正在尝试使用以下代码检查 DataGridView 单元格的单元格类型:

 Private Sub DataGridView1_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
        If DataGridView1.Columns(e.ColumnIndex).Name = "ColCheck" Then
            Dim cell As DataGridViewCell = DataGridView1.Rows(e.RowIndex).Cells("ColCheck")
            If cell Is DataGridViewCheckBoxCell Then

            End If

我得到DataGridViewCheckBoxCell 是一种类型,不能用作表达式。

【问题讨论】:

  • 它的工作.. 谢谢。但正如你所看到的,我可能从未发现过这个问题,因为它的标题完全不同。将此链接发布为答案,以便我标记它。

标签: .net vb.net datagridview


【解决方案1】:

我在单元格点击事件中试过这个并且效果很好:

Type str = dgv.Columns[dgv.SelectedCells[0].ColumnIndex].CellType;

【讨论】:

  • 谢谢,它对我有用。然后您可以检查属性 str.Name 并检查它是否是组合、文本...
【解决方案2】:

如果你知道行和列索引的另一种方法:dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].GetType().Name

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-15
    • 1970-01-01
    • 2012-05-15
    相关资源
    最近更新 更多