2009-12-16 58 views
3

我有一个DataGridView负责显示一些数据,我的两个列允许用户使用组合框输入。检测哪个列显示在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中编辑控件来自哪个列,以便我不为这两列运行此代码?

我是否错过了这样做的更好方法?

回答

3

怎么样e.Control.EditingControlDataGridView.CurrentCell.ColumnIndex?

或者只是DGV.CurrentCell.ColumnIndex?

+0

完美地工作!谢谢!有那么多控制,我很容易迷路。 – jrsconfitto 2009-12-17 14:39:31

+0

如果我想检查标题文本,该怎么办?就像... '如果DGV.Column.HeaderText =“xyz”那么' – Arbaaz 2013-11-11 04:24:17

+0

Nevermind,我找到了解决方案.. 'If DataGridView1.Columns(DataGridView1.CurrentCell.ColumnIndex).HeaderText =“Enter Quantity”Then' – Arbaaz 2013-11-11 04:42:21

相关问题