Skip to main content

Focus and Scroll Records

  • 4 minutes to read

This topic explains how to focus and scroll records in code. For example, you can:

  • scroll the view to a record and activate an editor
  • provide a custom control that navigates through records
  • scroll to a record that satisfies the condition

To learn how users can focus and scroll records, see Navigating Through Cells.

Focus and Scroll Records in Code

Use the following vertical grid’s API to focus and scroll records in code:

  • FocusedRecord — gets or sets the focused record’s zero-based index
  • RecordCount — gets the number of records
  • HorzScroll — scrolls the view by the specified number of records or bands if bands do not fit in the width
  • LeftVisibleRecord — gets or sets the index of the leftmost visible record

    image

  • MakeRecordVisible — scrolls the view to the specified record

    image

  • LocateByValue — returns the handle of the record that contains the specified value in the specified row/filed
  • LocateByDisplayText — returns the handle of the record that displays the specified text in the specified row
  • GetRecordIndex — returns the handle of the vertical grid record that corresponds to the data source record with the specified index
  • GetDataSourceRecordIndex — returns the index of the data source record that corresponds to the vertical grid record with the specified handle

Whether the focus moves when the view is scrolled, depends on the current layout:

Custom Data Navigator

This example shows how to create a custom data navigator. The control comprises navigation buttons and a check box as shown below.

ScrollingRecords - CustomNavigator

The table below lists the elements of this navigation panel, their names, and explains their purpose.

Element Description Name
ScrollingRecords - MoveFocus If checked, the navigation panel’s buttons move focus. Otherwise, they scroll the view horizontally. chbMoveFocus
ScrollingRecords - MoveFirst If the check box is checked, focuses the first record. Otherwise, scrolls the view so that the first record is visible leaving the focus unchanged. btnFirst
ScrollingRecords - MovePrev If the check box is checked, shifts focus backwards one record. Otherwise, scrolls the view left by one record leaving the focus unchanged. btnPrev
ScrollingRecords - ScrollToFocused Makes the focused record visible. btnShowFocused
ScrollingRecords - MoveNext If the check box is checked, shifts focus forward one record. Otherwise, scrolls the view right by one record leaving the focus unchanged. btnNext
ScrollingRecords - MoveLast If the check box is checked, focuses the last record. Otherwise, scrolls the view so that the last record is visible leaving the focus unchanged. btnLast

Handle the Click events as the code below shows. The vertical grid should apply the multiple records view to see the difference between when you move the focus and when you scroll the view.

private void btnShowFocused_Click(object sender, System.EventArgs e) {
   vGridControl1.MakeRecordVisible(vGridControl1.FocusedRecord);
}
private void btnFirst_Click(object sender, System.EventArgs e) {
   if (chbMoveFocus.Checked)
      vGridControl1.FocusedRecord = 0;
   else
      vGridControl1.LeftVisibleRecord = 0;
}
private void btnPrev_Click(object sender, System.EventArgs e) {
   if (chbMoveFocus.Checked)
      vGridControl1.FocusedRecord--;
   else
      vGridControl1.HorzScroll(-1);
}
private void btnNext_Click(object sender, System.EventArgs e) {
   if (chbMoveFocus.Checked)
      vGridControl1.FocusedRecord++;
   else
      vGridControl1.HorzScroll(1);
}
private void btnLast_Click(object sender, System.EventArgs e) {
   if (chbMoveFocus.Checked)
      vGridControl1.FocusedRecord = vGridControl1.RecordCount - 1;
   else
      vGridControl1.MakeRecordVisible(vGridControl1.RecordCount - 1);
}