【问题标题】:How to check the header text of a DataGridView column of a selected cell in Visual Basic如何在 Visual Basic 中检查选定单元格的 DataGridView 列的标题文本
【发布时间】:2017-10-10 13:01:21
【问题描述】:

我在 Visual Basic 中有一个 datagridview。我想调整一个子来完成以下任务:当用户在我的 DGV(单元格单击事件)中选择一个单元格时,我想检查列标题文本。在我的示例中,如果列的标题文本是“MinEquation”,那么我想执行一些事件。我不能使用列索引的原因是我在具有不同数据表的循环中动态创建了这些 DGV。如何对所选单元格的列标题文本进行比较运算符。谢谢!

【问题讨论】:

  • 您的单元格点击事件具有您点击的列的索引。使用该索引访问 DGV 的 Columns 数组。您创建列的顺序无关紧要。只需注意用户单击列 -1 的行标题即可。
  • 感谢您的帮助。我现在如何引用该网格视图?喜欢访问它的属性。
  • 每个事件处理程序的第一个参数是事件的发送者。它始终是一个对象,但由于您知道该事件来自您的 DGV,您可以 DirectCast(sender, DataGridView)。

标签: vb.net datagridview


【解决方案1】:

您将生成DataGridView 的CellClick event,然后使用DataGridViewCellEventArgs 返回列的信息。看看这个例子:

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    If DataGridView1.Columns(e.ColumnIndex).HeaderText = "MinEquation" Then
        'Match
    End If
End Sub

【讨论】:

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