gpt4 book ai didi

vb.net - 检测哪一列在数据 GridView 中显示编辑控件

转载 作者:行者123 更新时间:2023-12-02 00:43:07 29 4
gpt4 key购买 nike

我有一个 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 中的哪一列,这样我就不会为两列都运行此代码?

我是否缺少更好的方法?

最佳答案

e.Control.EditingControlDataGridView.CurrentCell.ColumnIndex 呢?

或者只是 DGV.CurrentCell.ColumnIndex?

关于vb.net - 检测哪一列在数据 GridView 中显示编辑控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1918216/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com