Skip to main content
All docs
V24.2

Troubleshooting: Focus and Select Rows

  • 4 minutes to read

This article helps you troubleshoot the most common issues with row focus and selection in the GridControl.

GridControl Automatically Selects the First Row

Problem

The GridControl automatically focuses the first row at startup.

First Row Is Focused

Solution

Disable the DataControlBase.AllowInitiallyFocusedRow property. In this case, the GridControl focuses or selects none of its rows on startup.

First Row Is Not Focused

Note

Once an end user focuses a row, the GridControl includes at least one focused row.

Users Cannot Focus Any Row or Cell in GridControl

Problem

You cannot focus any cell or row in the GridControl.

Solution

To allow row and cell focus in your GridControl, verify that the DataViewBase.NavigationStyle property is set to Cell for your GridControl.

GridControl Loses Selection and Focus After Setting a Data Source

Problem

When the ItemsSource of the GridControl is reset, the GridControl regenerates all its rows.

Solution

To retain selection, focus, expanded master rows, and other row settings in the GridControl, you must manually save these settings to local variables. You can now reset ItemsSource and manually restore your saved values.

The Focused Element’s Background Color Changes If the Control Loses Focus

Problem

When the GridControl loses focus, the selected row’s color fades.

Previous Row Is Selected

Solution

Set the view’s DataViewBase.FadeSelectionOnLostFocus property to false.

Previous Row Is Selected

Conditional Formatting Does Not Apply to Focused Rows or Cells

Problem

Format Conditions styles have a lower priority than the focused row background color.

Solution

To display highlighted cells and rows, handle the TableView.CustomRowAppearance and TableView.CustomCellAppearance events. Refer to the following example for more information: How to: Show the color determined by conditional formatting when a row is focused.

The Focused Row Is Not Highlighted When Multiple Selection Mode Is Enabled

Problem

If you use multiple row selection and set the DataControlBase.CurrentItem property in code, the focused row is not highlighted; only a dotted border is visible.

Solution

With multiple selection enabled, the DataControlBase.CurrentItem and DataControlBase.SelectedItem properties refer to different items. DataControlBase.CurrentItem manages the currently focused item, while DataControlBase.SelectedItem is for the selected object. To focus and highlight a row, specify both properties.

A Cell Editor Does Not Appear After You Set the CurrentItem and CurrentColumn Properties in Code Behind

Problem

After you change the DataControlBase.CurrentItem and DataControlBase.CurrentColumn properties in code behind, you cannot open the focused cell’s editor. This can happen if target rows are outside of the viewport.

Solution

Due to virtualization mechanisms, the GridControl should initialize the corresponding items for the target data rows. To prevent problems when opening a cell editor, use the BeginInvoke method to call the DataViewBase.ShowEditor method after you update the DataControlBase.CurrentItem and DataControlBase.CurrentColumn properties.

gridControl.CurrentItem = Items.First();
Dispatcher.BeginInvoke(new Action(() => {
    tableView.ShowEditor(true);          
}));

How to Disable Selection for Individual Rows and Cells

Problem

You want to prevent certain rows and cells from being selected.

Solution

Handle the following events: DataViewBase.CanSelectRow, TableView.CanSelectCell, DataViewBase.CanUnselectRow, and TableView.CanUnselectCell.

Problem Binding a ViewModel Property to the Selected Item Collection

Problem

You bind a ViewModel property to the DataControlBase.SelectedItems property of the GridControl. The property returns null even after a user selects rows.

Solution

Make sure that you initialize the ViewModel’s property with an empty collection. The GridControl adds selected items to an existing collection. It does not create a new collection every time selection changes.

Users Cannot Select Multiple Rows on a Touch Device

Problem

Users can only select rows with the help of Ctrl or Shift keys. They have no way to select multiple rows with touch gestures only.

Previous Row Is Not Selected

Solution

To enable touch-friendly multiple row selection, set the DataControlBase.SelectionMode property to MultiSelectMode.MultipleRow.

Previous Row Is Selected

How to Disable Multiple Row or Cell Selection

Problem

If the DataControlBase.SelectionMode property is set to Row or Cell, multi-selection is enabled.

Solution

To disable multi-selection, set DataControlBase.SelectionMode to None.

GridControl Loses Keyboard Focus

Problem

The GridControl loses keyboard focus when its cell editor is closed. This problem can occur if the GridControl is located inside a container, such as a ScrollViewer. The container control can steal keyboard focus.

Solution

Disable the container’s Focusable property.