Xceed Grid for WinForms v4.3 Documentation
How to change the behavior of the Enter key

Welcome to Xceed Grid for WinForms v4.3 > Task-Based Help > Mouse and keyboard > How to change the behavior of the Enter key

By default, pressing Enter on a cell or row that is not being edited, will do nothing while pressing Enter on a cell or row that is being edited will commit the modifications. In order to change the default behavior of the Enter key, the grid's ProcessCmdKey method must be overridden.

Demonstration

The following examples demonstrates how to change the behavior of the Enter key so that when enter is pressed the focus will go to the next cell:

VB.NET Copy Code

Protected Overrides Function ProcessCmdKey ( ByRef msg As Message, _
                                             ByVal keyData As Keys ) As Boolean

  ' ProcessCmdKey is only used for the Enter and the Escape keys.
  If keyData = Keys.Enter Then

    ' Move to the next cell on the right when the enter key is pressed
    Me.MoveCurrentCell( HorizontalDirection.Right )
    Me.CurrentCell.BringIntoView()

    Return True
  End If

  Return MyBase.ProcessCmdKey( msg,keyData )
End Function

C# Copy Code

protected override System.Boolean ProcessCmdKey ( ref Message msg , Keys keyData)
{
  // ProcessCmdKey is only used for the Enter and the Escape keys.
  if( keyData == Keys.Enter )
  {
    // Move to the next cell on the right when the enter key is pressed
    this.MoveCurrentCell( HorizontalDirection.Right );
    this.CurrentCell.BringIntoView();

    return true;
  }
  return base.ProcessCmdKey( ref msg,keyData );
}