Home Forums WinForms controls Xceed Grid for WinForms How to change the behavior of the Enter key

Viewing 1 post (of 1 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17817 |

    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.

    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

    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#

    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 );
    }

    Imported from legacy forums. Posted by Xceed admin (had 818 views)

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.