我有一个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
这允许在DGV的两个组合框中都输入用户输入,但我只想允许一个组合框进行用户输入。
有没有办法检测DGV中编辑控件来自哪一列,以便我不会为两个列运行此代码?
我是否错过了更好的方法?
If DGV.Column.HeaderText="xyz" then
- SamuraiJack如果 DataGridView1.Columns(DataGridView1.CurrentCell.ColumnIndex).HeaderText = "输入数量" Then
- SamuraiJack