关于vb.net:检测在datagridview中哪一列显示了编辑控件

Detect which column is showing an editing control in a datagridview

我有一个DataGridView负责显示一点数据,我的两列允许用户使用组合框输入。

麻烦的是,一列只需要在列表中显示预设值,而另一列则需要既显示预设又允许用户输入自己的值。

我通过使用以下代码显示组合框的编辑控件来完成此操作:

1
2
3
4
5
6
7
Private Sub DGV_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DGV.EditingControlShowing
    'todo: figure out which control is being edited (the reason or the action) and only allow the action column to allow user input
    If TypeOf e.Control Is DataGridViewComboBoxEditingControl Then
        Dim cb As ComboBox = e.Control
        cb.DropDownStyle = ComboBoxStyle.DropDown
    End If
End Sub

这允许在DGV中的两个组合框上输入用户信息,但是我只想允许其中一个组合框的用户输入。

是否有任何方法可以检测到编辑控件来自DGV中的哪一列,这样我就不会同时为这两列运行此代码?

我错过了更好的方法吗?


关于e.Control.EditingControlDataGridView.CurrentCell.ColumnIndex呢?

或者只是DGV.CurrentCell.ColumnIndex?