检测哪个列在datagridview中显示编辑控件 [英] Detect which column is showing an editing control in a datagridview
问题描述
麻烦的是,一列只需要在其列表中显示预设值,但另一个需要显示预设值,并允许用户输入自己的值。
我通过显示编辑来完成此操作控制组合框使用这一段代码:
Private Sub DGV_EditingControlShowing(ByVal sender As System.Object,ByVal e As System。 Windows.Forms.DataGridViewEditingControlShowingEventArgs)处理DGV.EditingControlShowing
/ pre>
'todo:找出正在编辑的控件(原因或操作),并且只允许操作列允许用户输入
如果TypeOf e.Control DataGridViewComboBoxEditingControl然后
Dim cb As ComboBox = e.Control
cb.DropDownStyle = ComboBoxStyle.DropDown
End If
End Sub
这允许在DGV的 组合框中的用户输入,但我只希望允许用户输入其中一个。
有没有办法检测编辑控件来自哪个列,以便我不为两列运行这个代码?
我错过了更好的方式这样做?
解决方案e.Control.EditingControlDataGridView.CurrentCell.ColumnIndex?
或者也可能只是DGV.CurrentCell.ColumnIndex?
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?
解决方案What about e.Control.EditingControlDataGridView.CurrentCell.ColumnIndex?
Or maybe just DGV.CurrentCell.ColumnIndex?
这篇关于检测哪个列在datagridview中显示编辑控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!