1 Previous Next 

DataGridView: Implement Single click navigation to a DataGridView Combo Box Cell


When you navigate to a DataGridView combobox column you need to click on the cell twice to get the drop down to show.  Valentine Khorzhevsky came up with an way to get the drop down to show on the first click using SendKeys.  Matthew Hicks added a second code sample which works if you have a DataGridViewCheckBoxColumn in the DataGridView.  The DataGridViewCheckBoxColumn does not have an edit type.

    Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
        Dim dgv As DataGridView = CType(sender, DataGridView)

        If dgv(e.ColumnIndex, e.RowIndex).EditType.ToString() = "System.Windows.Forms.DataGridViewComboBoxEditingControl" Then
            SendKeys.Send("{F4}")
        End If
    End Sub


 

    Private Sub dgvReceiptItems_CellEnter(ByVal sender As Object, _

        ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _

        Handles dgvReceiptItems.CellEnter

        Dim dgv As DataGridView = CType(sender, DataGridView)

 

        If dgv(e.ColumnIndex, e.RowIndex).EditType IsNot Nothing Then

            If dgv(e.ColumnIndex, e.RowIndex).EditType.ToString() = "System.Windows.Forms.DataGridViewComboBoxEditingControl" Then

                SendKeys.Send("{F4}")

            End If

        End If

    End Sub

 




1 Previous Next