Detect which column is showing an editing control in a datagridview

二次信任 提交于 2020-01-14 14:14:15

问题


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 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?


回答1:


What about e.Control.EditingControlDataGridView.CurrentCell.ColumnIndex?

Or maybe just DGV.CurrentCell.ColumnIndex?



来源:https://stackoverflow.com/questions/1918216/detect-which-column-is-showing-an-editing-control-in-a-datagridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!