Using up and down arrow keys in datagridview

A

Andrus

I have combobox column in DataGridView.
Up and down error keys should be used to navigate previous and next row in
grid.

For this I override them in ProcessCmdKey() event.

When combobox dropdown menu is open arrow arrow keys should move to previous
and next item in
dropdown menu instead of moving betveen rows.
How to check that combobox dropdown menu is open in ProcessCmdKey() ?

Andrus.


protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {

const int WM_SYSKEYDOWN = 0x104;

if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN)) {
switch (keyData) {
case Keys.Down:
if (this.CurrentCell is DataGridViewComboBoxCell) {
CurrentCell = Rows[CurrentCell.RowIndex +
1].Cells[CurrentCell.ColumnIndex];
return true;
}
break;

case Keys.Up:
if (this.CurrentCell is DataGridViewComboBoxCell) {
CurrentCell = Rows[CurrentCell.RowIndex -
1].Cells[CurrentCell.ColumnIndex];
return true;
}
break;
}
return base.ProcessCmdKey(ref msg, keyData);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top