Focus and Scroll Rows

  • 3 minutes to read

The vertical and property grid controls allow you to navigate through rows in code. Typical scenarios:

  • focus a specific row;
  • scroll to a specific row without focusing it;
  • ensure that multiple rows are visible simultaneously;
  • display a specific row at the top of the grid;
  • synchronize the grid with a control that displays related data.

This topic describes how to focus rows and scroll the view vertically. To learn how to focus records and scroll the view horizontally, see Focus and Scroll Records. To learn how users can focus cells and scroll the view, see Navigating Through Cells.

Focus a Row in Code

Use the following API to focus records in code:

The following sample code focuses the rowPrice row if it is visible. Otherwise, the first visible row is focused.

if (rowPrice.Visible)
   vGridControl1.FocusedRow = rowPrice;
else 
   vGridControl1.FocusFirst();

The example below shows how to automatically invoke the next cell's editor when the current cell is completed. When the last row is edited, focus moves to the next record.

private void vGridControl1_HiddenEditor(object sender, System.EventArgs e) {
   VGridControl vGrid = sender as VGridControl;
   MoveNext(vGrid);
   while ((vGrid.FocusedRow is CategoryRow) || !vGrid.CanShowEditor)
      MoveNext(vGrid);
   vGrid.ShowEditor();
}

// Moves focus to the next row or to the first row when the last one has been achieved.
private void MoveNext(VGridControl grid) {
   if (grid.FocusedRow == grid.GetLastVisible()) {
      grid.FocusFirst();
      grid.FocusedRecord++;
   }
   else 
      grid.FocusNext();
}

Scroll Rows in Code

Use the following API to scroll records in code: