windowsforms-483-controls-and-libraries-vertical-grid-data-layout-records-rows-and-cells-rows-focus-and-scroll-rows.md
The vertical and property grid controls allow you to navigate through rows in code. Typical scenarios:
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.
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();
If rowPrice.Visible Then
VGridControl1.FocusedRow = rowPrice
Else
VGridControl1.FocusFirst()
End If
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();
}
Private Sub VGridControl1_HiddenEditor(ByVal sender As Object, ByVal e As System.EventArgs) Handles VGridControl1.HiddenEditor
Dim vGrid As VGridControl = sender
MoveNext(vGrid)
While ((TypeOf (vGrid.FocusedRow) Is CategoryRow) Or Not vGrid.CanShowEditor)
MoveNext(vGrid)
End While
vGrid.ShowEditor()
End Sub
' Moves focus to the next row or to the first row when the last one has been achieved.
Private Sub MoveNext(ByVal Grid As VGridControl)
If Grid.FocusedRow Is Grid.GetLastVisible() Then
Grid.FocusFirst()
Grid.FocusedRecord += 1
Else
Grid.FocusNext()
End If
End Sub
Use the following API to scroll records in code:
VGridControlBase.ScrollVisibility — gets or sets whether the vertical scroll bar is visible.
VGridControlBase.MakeRowVisible — scrolls the view up or down up to the specified row and expands its parent rows if required.
VGridControlBase.TopVisibleRowIndex — gets or sets the zero-based index of the top visible row.
VGridControlBase.VertScroll — scrolls the view by up or down the specified number of rows.