C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
However: When I went to open the dialog again, the selection would not be in the same place.
Tip: We can combine PreviewKeyDown and KeyDown. Take KeyDown, and set its event Handled property to true.
Example of KeyDown event handler: C#
void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
//
// Set the key down event has handled. We call our function
// ProceedOpen in the PreviewKeyDown event instead.
//
if (e.KeyCode == Keys.Enter)
{
e.Handled = true;
}
}
Example of PreviewKeyDown event handler: C#
void dataGridView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
//
// If the key pressed is enter, then call ProceedOpen.
//
if (e.KeyCode == Keys.Enter)
{
ProceedOpen();
}
}