Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / UltraGrid Keyboard navigation with left and right arrow keys.

UltraGrid Keyboard navigation with left and right arrow keys.

New Discussion
Kipp Woodard
Kipp Woodard asked on Nov 2, 2017 1:33 PM

I’m expecting that I’ll need to custom code for this, but I want to ask before I do.

If I am in edit mode of a cell, before the first character position, and I hit left-arrow, I want to move focus to the previous cell of the row, or last cell of the previous row if I am in the first column.

If I am in edit mode of a cell, after the last character position, and I hit right-arrow, I want to move focus to the next cell of the row, or first cell of the next row if I am in the last column.

Sign In to post a reply

Replies

  • 0
    Mike Saltzman
    Mike Saltzman answered on Nov 1, 2017 8:44 PM

    Hi Kipp,

    There’s no really simple way to do this. Typically, the arrows keys move within the cell and the Tab (or shift+tab) key moves between cells.

    It is, of course, easy enough to trap KeyDown (or KeyUp) and watch for the left and right arrow keys. But then you would have to detect if the caret is in the first or last position. This is a little trickier. I guess if you grid is very simple and every cell is just showing plain text, it would be pretty straightforward. But if you are using other editors like dropdown lists, masked cells, or FormattedText, you would have to handle each case separately, since each editor does something slightly different. You might be able to get it to work in some generic way by accessing the properties of the editor, but the behavior would still be a little weird because once you arrowed into a cell that doesn’t enter edit mode, like for example a Checkbox cell, you would be in selection mode instead of edit mode.

    Anyway… if you want to try to go down that path (or if your grid is, in fact, simple and just has text cells), then here’s some code I threw together that seems to work in a very basic test.

            private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
            {
                var grid = (UltraGrid)sender;
                var activeCell = grid.ActiveCell;
                if (null == activeCell ||
                    false == activeCell.IsInEditMode)
                {
                    return;
                }
    
    
    
    
                var editor = activeCell.EditorResolved;
                if (false == editor.SupportsSelectableText)
                    return;
    
    
    
    
                switch (e.KeyCode)
                {
                    case Keys.Left:
                        if (editor.SelectionStart == 0)
                        {
                            e.Handled = true;
                            e.SuppressKeyPress = true;
                            grid.PerformAction(UltraGridAction.PrevCellByTab);
                            grid.PerformAction(UltraGridAction.EnterEditMode);
                        }
                        break;
                    case Keys.Right:
                        if (editor.SelectionStart == editor.TextLength)
                        {
                            e.Handled = true;
                            e.SuppressKeyPress = true;
                            grid.PerformAction(UltraGridAction.NextCell);
                            grid.PerformAction(UltraGridAction.EnterEditMode);
                        }
                        break;
                }
            }

     

    • 0
      Kipp Woodard
      Kipp Woodard answered on Nov 2, 2017 1:33 PM

      Thanks.  Very helpful…  again.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Kipp Woodard
Favorites
0
Replies
2
Created On
Nov 02, 2017
Last Post
8 years, 3 months ago

Suggested Discussions

Created by

Created on

Nov 2, 2017 1:33 PM

Last activity on

Feb 23, 2026 3:07 PM