Focus and Navigation

  • 4 minutes to read

In this topic you will learn how to perform the following tasks:

  • Switch between navigation styles: row, cell, or no input focus.
  • Focus rows in code or determine the currently focused row.
  • Focus cells in code or determine the cell focused by the end user.

Use the DataViewBase.NavigationStyle property to control how users can move focus in the GridControl:

Property Value Description
GridViewNavigationStyle.Row A View allows you to focus and navigate through rows only.
GridViewNavigationStyle.Cell (Default) A View displays the focused row and allows you to focus, navigate and edit cells.
GridViewNavigationStyle.None A View does not allow you to focus rows and cells.

Refer to the Navigate Through Rows and Cells topic for information about end-user navigation.

Focus Rows, Nodes, and Cards

Availability

Users can focus rows, nodes, and cards if the DataViewBase.NavigationStyle property is not set to GridViewNavigationStyle.None.

In Code

To identify the focused row, node, or card, use the DataControlBase.CurrentItem / DataViewBase.FocusedRowHandle properties. In addition you can use the TreeListView.FocusedNode property to get or set the focused node.

The following code sample shows how to focus a row that contains the specified cell value:

void Button_Click(object sender, RoutedEventArgs e) {
    FocusRowInGrid();
}

public void FocusRowInGrid() {
    view.FocusedRowHandle = 2;
}

The GridControl provides the following methods to move the row/card focus:

Method Description
DataViewBase.MoveFirstRow Moves focus to the first visible row or card within a View.
DataViewBase.MovePrevPage Moves focus backward by the number of rows or cards displayed onscreen within a View.
DataViewBase.MovePrevRow Moves focus to the row or card that precedes the one currently focused.
DataViewBase.MoveNextRow Moves focus to the row or card that follows the one currently focused.
DataViewBase.MoveNextPage Moves focus forward by the number of rows or cards displayed onscreen within a View.
DataViewBase.MoveLastRow Moves focus to the last visible row or card within a View.
DataViewBase.MoveFocusedRow Moves focus to the specified row.
GridViewBase.MoveParentGroupRow Moves focus to the group row that owns the currently focused row.

You cannot use this methods to focus hidden rows or rows from collapsed groups/details. The DataControlBase.VisibleRowCount property returns the number of visible rows.

The following table lists events that GridControl raises when a focused row is changed:

Event Description
DataControlBase.CurrentItemChanged Occurs after the focused row/card changes. Provides the information about the previous and current focused data item.
DataViewBase.FocusedRowHandleChanged Occurs after the focused row/card's handle changes. Provides the information about the previous and current focused row handle.

When the GridControl is loaded, it focuses the first row/card. To load the GridControl without a focused row/card, set the DataControlBase.AllowInitiallyFocusedRow property to false.

The GridControl scrolls its View to the focused row/card. To disable this behavior, set the DataViewBase.AllowScrollToFocusedRow property to false.

Focus Cells

Availability

To allow users to focus cells, check that the DataViewBase.NavigationStyle property is set to GridViewNavigationStyle.Cell (default value).

In Code

To identify the focused cell, use a combination of the DataControlBase.CurrentItem / DataViewBase.FocusedRowHandle and DataControlBase.CurrentColumn properties.

The following code sample shows how to focus a cell with the specified value:

void Button_Click(object sender, RoutedEventArgs e) {
    FocusCellInGrid();
}

public void FocusCellInGrid() {
    grid.CurrentColumn = view.VisibleColumns[2];
    view.FocusedRowHandle = 0;
}

Use the following methods to move the cell focus within a row:

Method Description
DataViewBase.MoveNextCell Focuses the next cell after the focused cell.
DataViewBase.MovePrevCell Focuses the previous cell before the focused cell.

Set the column's ColumnBase.AllowFocus property to false to prohibit end users from focusing this column.

End users can press the Tab key to move focus to the next cell. To exclude a column from the tab order, set its ColumnBase.TabStop property to false.

See Also