我有一个 DataGridView 负责显示一些数据,我的两列允许用户使用组合框输入。
问题在于,一列只需要在其列表中显示预设值,但另一列需要显示预设并允许用户输入自己的值。
我通过使用以下代码显示组合框的编辑控件来实现此目的:
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
这允许用户输入bothDGV 中的组合框,但我只想允许用户输入其中之一。
有什么方法可以检测编辑控件来自 DGV 中的哪一列,这样我就不会为两列运行此代码?
我是否缺少更好的方法来做到这一点?
e.Control.EditingControlDataGridView.CurrentCell.ColumnIndex 怎么样?
或者也许只是 DGV.CurrentCell.ColumnIndex?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)