Detect which column is showing an editing control in a datagridview
i have a DataGridView responsible for showing a bit of data and two of my columns allow for user input using comboboxes.
The trouble is that one column only needs to show preset values in it's list, but the other needs to both show the presets and allow for the user to enter in their own values.
i accomplish this by showing the editing control for the combobox with this bit of开发者_如何学Go code:
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
This allows for user input on both comboboxes in the DGV, but i only want to allow for user input for one of them.
Is there any way to detect which column in the DGV the editing control is coming from so that i dont run this code for both columns?
Am i missing a better way of doing this?
What about e.Control.EditingControlDataGridView.CurrentCell.ColumnIndex?
Or maybe just DGV.CurrentCell.ColumnIndex?
精彩评论