John,
First, you have to be using your own Grid, sub-classed from the DataGridView.
Next, in your sub-class, you need to override the ProcessCmdKey() method. You'll want something like this (this code uses a switch-case, to add code for trapping other keys):
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;
if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
switch (keyData)
{
case Keys.Enter:
return true;
}
}
return base.ProcessCmdKey(ref msg, keyData);
}
~~Bonnie
>When you press Enter on a record in a datagridview, focus moves to the next record. Can anyone tell me how to prevent this behaviour ie remain on the same record when Enter is pressed. I want to choose a record and hide the datagridview using the keyboard, not the mouse.
>
>Any help appreciated.