如何在使用VB.NET编辑DataGridView中的单元格时获取当前列索引

如何在使用VB.NET编辑DataGridView中的单元格时获取当前列索引,vb.net,datagridview,Vb.net,Datagridview,我有一个带有5列的DataGridView。 第1列和第5列的单元格是组合框。 我有一个函数,每当我更改这些组合框时都会运行 现在,为了让函数正常运行,我必须得到我编辑的组合框属于哪一列 就像,当我更改属于第1列的组合框时,Function 1会运行。 当我更改属于第5列的组合框时,函数2将运行。啊,我真傻 DataGridView.CurrentCellAddress.X 'Column DataGridView.CurrentCellAddress.Y 'Row 或 然后,如果您在Da

我有一个带有5列的
DataGridView

第1列和第5列的单元格是组合框。
我有一个函数,每当我更改这些组合框时都会运行

现在,为了让函数正常运行,我必须得到我编辑的组合框属于哪一列

就像,当我更改属于第1列的组合框时,
Function 1
会运行。
当我更改属于第5列的组合框时,
函数2
将运行。

啊,我真傻

DataGridView.CurrentCellAddress.X 'Column  
DataGridView.CurrentCellAddress.Y 'Row

然后,如果您在
DataGridView
中有预定义的列(例如,列的名称将是
DataGridView\u ComboBoxOne
),并且不希望硬编码索引比较

您可以这样使用:

Select case DataGridView.CurrentCell.ColumnIndex 
    Case DataGridView_ComboBoxOne.Index
        Function1()
    Case DataGridView_ComboBoxTwo.Index
        Function2()
    Case Else
        'Update of other columns
End Select

这是在不使用当前单元格的情况下获取列索引的直接方法。在DataGridView1\u ColumnHeaderMouseClick下使用它。

谢谢。”CurrentCell.ColumnIndex和CurrentCellAddress.Y的工作原理相同。但我将使用“CurrentCell.ColumIndex”,因为它更“可读”。我还测试了你的其他代码,效果也很好。真的,很好,还有新的信息,]谢谢[^_^
Select case DataGridView.CurrentCell.ColumnIndex 
    Case DataGridView_ComboBoxOne.Index
        Function1()
    Case DataGridView_ComboBoxTwo.Index
        Function2()
    Case Else
        'Update of other columns
End Select
Dim columnIndex as Integer

columnIndex = e.ColumnIndex