Home Forums WinForms controls Xceed Grid for WinForms Changing the current row

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #15876 |

    I have a grid set up with InactiveSelectionBackColor and InactiveSelectionForeColor set to the same values as SelectionBackColor and SelectionForeColor, respectively. I also have AllowCellNavigation set to false.

    This gives me the desired effect I want, that is, the grid shows the selected row in the same colors whether or not is has focus, and the entire row is always highlighted.

    When the grid has focus:
    Up-Arrow = select the previous row.
    Down-Arrow = select the next row.
    Page-Up = moves up a page
    Page-Down = moves down a page
    Ctrl-Page-Up = moves to the first row
    Ctrl-Page-Down = moves to the last row

    I want to be able to make all these moves by calling grid methods when some other control has focus. How can I do this???

    PS: I can use MoveCurrentRow(), and the current row changes, but the highlight doesn’t redraw until the grid gets focus and you press one of the above keys.

    Imported from legacy forums. Posted by Glenn (had 3887 views)

    User (Old forums)
    Member
    Post count: 23064

    Figured out how to do this myself:

    grd.MoveCurrentRow(Xceed.Grid.VerticalDirection.*);
    grd.CurrentRow.BringIntoView();
    grd.SelectedRows.Clear();
    grd.SelectedRows.Add(grd.CurrentRow);

    Imported from legacy forums. Posted by Glenn (had 2981 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello there..

    If you still haven’t found the solution for mentioned problem here it is…

    After calling MoveCurrentRow, current row is changed, but it still has to be selected:

    this.gridControl1.CurrentView.IsSelected = true;

    This in the other hand causes previous row to remain selected, so before MoveCurrentRow call, be sure to deselect currently selected row(s):

    this.gridControl1.SelectedRows.Clear();

    At the end I would also recommend to call BringIntoView method, which will bring newly selected row into visible part of the grid (important on page up, page down features).

    Whole method:

            protected void MoveRowCurrentRowSelection(VerticalDirection direction)
            {
                this.gridControl1.SelectedRows.Clear();

                this.gridControl1.MoveCurrentRow(direction);
                if (gridControl1.CurrentRow != null)
                {
                    this.gridControl1.CurrentRow.IsSelected = true;
                    this.gridControl1.CurrentRow.BringIntoView();
                }
            }

    Imported from legacy forums. Posted by Ogren (had 2629 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.