After I set "EditOnEnter" to be true, the DataGridViewComboBoxCell
still takes two clicks to open if I don't click on the down arrow part of the combo box.
Anyone have any clue how to fix this? I've got my own DataGridView
class that I use, so I can easily fix this issue system-wide with a few smart event handlers I hope.
Thanks.
see: VB.NET Controls inside of a DataGridView Row on a Windows Form
Since you already have the
DataGridView
'sEditMode
property set to "EditOnEnter", you can just override itsOnEditingControlShowing
method to make sure the drop-down list is shown as soon as a combo box receives focus:Whenever an edit control in your
DataGridView
control gets the input focus, the above code checks to see if it is a combo box. If so, it virtually "presses" the F4 key, which causes the drop-down portion to expand (try it when any combo box has the focus!). It's a little bit of a hack, but it works like a charm.I used this solution as it avoids sending keystrokes:
Override the OnCellClick method (if you're subclassing) or subscribe to the CellClick event (if you're altering the DGV from another object rather than as a subclass).
To avoid the SendKeys issues, try the solution from Open dropdown(in a datagrid view) items on a single click. Essentially, in OnEditingControlShowing hook to the Enter event of the combo box, in the Enter event handler, set ComboBox.DroppedDown = true. That seems to have the same effect, but without the side effects @Cody Gray mentions.