0

I'm working on a project where I use a DataGridView, with some of the columns being DataGridViewComboBoxColumn.
My users want to edit these ComboBoxCell by pressing Down key.

I've actually two ideas on how doing it:

  1. Change the key that starts editing mode of these cells to Down key
  2. Check event Keydown on my DataGridView and if CurrentCell is a ComboBoxCell force the dropdown of this cell

But I didn't manage to find a way to do any of these.

So, Is there a way to achieve this? (Even if it doesn't use one of my ideas)

GoldenAge
  • 2,918
  • 5
  • 25
  • 63
Zoma
  • 321
  • 7
  • 20

1 Answers1

1

You can use DataGridView.KeyDown event:

Private Sub DataGridView1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown

    If e.KeyValue = Keys.Down Then
        With Me.DataGridView1
            If .Columns(.CurrentCell.ColumnIndex).GetType.Name = "DataGridViewComboBoxColumn" Then
                If Not .IsCurrentCellInEditMode Then
                    .BeginEdit(True)
                    CType(.EditingControl, ComboBox).DroppedDown = True
                    e.Handled = True
                End If
            End If
        End With
    End If

End Sub

Sorry, VB.NET code but you can easily translate it to C#.

tezzo
  • 10,858
  • 1
  • 25
  • 48
  • Thanks a lot for this, with your help I figured out how to make it work. Now I have to handle Down/Up Key to navigate into the dropdown. – Zoma Mar 01 '19 at 08:56