Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I prevent moving to the next cell in a DataGrid when the user is actively editing the cell and presses Enter?

Override the method ProcessKeyPreview in the DataGrid.

protected override bool ProcessKeyPreview( ref Message m )
{
  Keys keyCode = (Keys) (int) m.WParam & Keys.KeyCode;
  if ( ( m.Msg == WM_KEYDOWN || m.Msg == WM_KEYUP )
    && keyCode == Keys.Enter )
    return false;
  return true;
}

Contributed from George Shepherd's Windows Forms FAQ



Page view counter