将组合框单元格上的双击激活更改为单击?

时间:2014-07-08 17:30:54

标签: vb.net datagridview datagridviewcombobox

我的代码中有一个设置,其中有一个datagridview。对于每一行,我有一个组合框单元格,我有一个单独的组合框单元格,因为我想为每个单元格选择不同的项目。

问题:双击箭头时,单元格才会下降。如何更改单元格格式,或者可能更改单元格单击事件,以便单元格响应只需单击一次?

这是我的细胞创建代码。坦率地说,我没有启动任何其他代码,因为我不知道要触摸或调用什么事件。我可以编辑一个属性吗?

代码:

           'add items to combobox list 
            Dim comboCell As New DataGridViewComboBoxCell 
            comboCell.FlatStyle = FlatStyle.Flat
            Dim resolutionList As New List(Of cmbStruct)

            Dim currentResIndex As Integer = 0

            'create list of resolutions
            For j As Integer = 0 To resolutions.Length - 1

                Dim resClass As New cmbStruct
                resClass.Name = resolutions(j)
                resClass.ID = resolutions(j)
                resolutionList.Add(resClass)
                comboCell.Items.Add(resolutions(j))

              Next

            'set combocell values
            comboCell.DisplayMember = "Name"
            comboCell.ValueMember = "ID"

           'set the default value to the current resolution index 

            Try
                comboCell.Value = resolutions(currentResIndex) 
            Catch ex As Exception

            End Try

            comboCell.ValueType = GetType(cmbStruct)
            comboCell.DataSource = resolutionList
            editCameraTable("Resolution", i) = comboCell

        Next

2 个答案:

答案 0 :(得分:2)

更改EditMode属性:

DataGridView1.EditMode = DataGridViewEditMode.EditOnEnter

答案 1 :(得分:1)

似乎有一个几乎相同的问题和一个非常好的答案。它涉及使用click_event。链接在这里: How to manually drop down a DataGridViewComboBoxColumn?

在链接中:

Private Sub cell_Click(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles      DataGridView1.CellClick
    DataGridView1.BeginEdit(True)
    If DataGridView1.Rows(e.RowIndex).Cells(ddl.Name).Selected = True Then
        DirectCast(DataGridView1.EditingControl, DataGridViewComboBoxEditingControl).DroppedDown = True
    End If
End Sub