New to Telerik UI for WPF? Download free 30-day trial

Programmatic Selection

Select Cell Region

RadVirtualGrid supports selection of a cell region. This mechanism can be manipulated through the SelectCellRegion method. It has two overloads.

  • SelectCellRegion(Telerik.Windows.Controls.VirtualGrid.CellRegion) - Expects a single CellRegion.

  • SelectCellRegion(IEnumerable) - Expects multiple CellRegion elements.

Example 1: Selecting a CellRegion

 this.VirtualGrid.SelectCellRegion 
            (new Telerik.Windows.Controls.VirtualGrid.CellRegion(1, 1, 2, 5)); 

Figure 1: Selecting a CellRegion

Selecting a CellRegion

Unselect Cell Region

The control also provides a method for deselecting a CellRegion, or multiple CellRegions.

  • UnselectCellRegion(Telerik.Windows.Controls.VirtualGrid.CellRegion)

  • UnselectCellRegion(IEnumerable)

Selected Index, Selected Indexes and ToggleIndexSelection

The control supports programmatic selection based on a given index/indexes. For this purpose, the SelectedIndex and SelectedIndexes properties are exposed, as well the ToggleIndexSelection method.

The index based selection of RadVirtualGrid can be utilized only when the SelectionUnit of the control is set to Row or Column. Depending on the property value, the control will operate with either the index/indexes of the rows, or the columns.

  • SelectedIndex: Provides information regarding the selected index of the control and can be assigned as well.

  • SelectedIndexes: Provides information regarding the selected indexes. As it is a readonly collection, it cannot be assigned and items cannot be added to it.

  • ToggleIndexSelection: Selects the given index if it is not selected, or deselects if it is already selected. The unit that will be selected depends on the value of the SelectionUnit property. When using this method, the SelectedIndexes collection will be updated. Thus, using it is recommended when the application logic depends on the SelectedIndexes collection.

Example 2: Setting the SelectedIndex property

this.VirtualGrid.SelectedIndex = 1; 

Figure 2: Setting the SelectedIndex property

Setting the SelectedIndex property

See also

In this article