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 make the Enter key behave like the Tab key in a DataGrid, moving to the next cell?

You can override ProcessCmdKey, catch the Enter key, and swap it for a Tab key by sending a Tab, and not processing the Enter key.

public class CustomDataGrid : DataGrid
{
  protected override bool ProcessCmdKey( ref Message msg, Keys keyData )
  {
    if ( msg.WParam.ToInt32() == (int) Keys.Enter )
    {
      SendKeys.Send( "{Tab}" );
      return true;
    }
    return base.ProcessCmdKey( ref msg, keyData );
  }
}

Contributed from George Shepherd's Windows Forms FAQ



Page view counter