Articles in this section
Category / Section

How to navigate to the header cells using arrow keys in WinForms GridControl?

1 min read

Navigate to header cells

You can handle the Grid control's keydown event and navigate to the header cells.

C#

void gridControl1_KeyDown(object sender, KeyEventArgs e)
{
   //get the current cell position
   GridCurrentCell cc = this.gridControl1.CurrentCell;
   Keys Keycodes = e.KeyCode & Keys.KeyCode;
   switch (Keycodes)
   {
      //if left arrow pressed in the keyboard
      case Keys.Left:
              if (cc.ColIndex == 1)
              {
                 cc.MoveTo(cc.RowIndex, 0);
              }
              break;
      //if up arrow pressed in the keyboard
      case Keys.Up:
              if (cc.RowIndex == 1)
              {
                 cc.MoveTo(0, cc.ColIndex);
              }
              break;
   }
}

VB

Private Sub gridControl1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
   'get the current cell position
   Dim cc As GridCurrentCell = Me.gridControl1.CurrentCell
   Dim Keycodes As Keys = e.KeyCode And Keys.KeyCode
   Select Case Keycodes
       'if left arrow pressed in the keyboard
       Case Keys.Left
                If cc.ColIndex = 1 Then
                  cc.MoveTo(cc.RowIndex, 0)
                End If
       'if up arrow pressed in the keyboard
       Case Keys.Up
                If cc.RowIndex = 1 Then
                  cc.MoveTo(0, cc.ColIndex)
                End If
       End Select
End Sub

 

Samples:

C#: Navigate to Header Cells

VB: Navigate to Header Cells

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied