Reputation: 13649
I have a DataGridView with a KeyDown event.
void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.C && e.Modifiers == (Keys.Control | Keys.Shift))
{
MessageBox.Show("ok"); // to test if working
}
}
The message box prompts when I press the key combinations.
But that is only when the datagridview is empty (no rows of data).
The code doesn't work when the datagridview has rows already.
Is there any wrong with the codes?
Upvotes: 2
Views: 4219
Reputation: 17428
I believe you are going to have to derive from the DataGridView class in order to get the key processing you want. Another alternative would be to add a message filter, but I would go with the derived data grid as my first approach.
Upvotes: 0
Reputation:
The KeyDown
event handler doesn't fire when the DataGridView is in edit mode.
Upvotes: 3
Reputation: 936
The datagridview has child controls with their own events. I think you need to catch the row and/or cell keydown events too.
Upvotes: 0