# 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\<Telerik.Windows.Controls.VirtualGrid.CellRegion>)** - Expects multiple **CellRegion** elements.

**Example 1: Selecting a CellRegion**

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

> caption Selecting a CellRegion

![Selecting a CellRegion](https://www.telerik.com/products/wpf/documentation/assets/65ee182339f58e5f44e1a9167083d558/radvirtualgrid_selection_03.png)

## Unselect Cell Region

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

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

* **UnselectCellRegion(IEnumerable\<Telerik.Windows.Controls.VirtualGrid.CellRegion>)**

## 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**

```C#
this.VirtualGrid.SelectedIndex = 1;
```

> caption Setting the SelectedIndex property

![Setting the SelectedIndex property](https://www.telerik.com/products/wpf/documentation/assets/fba05fc4460bd312a3543bdb6e002daa/radvirtualgrid_selection_04.png)

## See Also

* [Selection](https://www.telerik.com/products/wpf/documentation/controls/radvirtualgrid/selection/selection)

* [Multiple Selection](https://www.telerik.com/products/wpf/documentation/controls/radvirtualgrid/selection/multiple-selection)

* [Editing](https://www.telerik.com/products/wpf/documentation/controls/radvirtualgrid/features/editing)

* [Insert and Remove Data](https://www.telerik.com/products/wpf/documentation/controls/radvirtualgrid/features/insert-and-remove-data)

* [Pinned Rows and Columns](https://www.telerik.com/products/wpf/documentation/controls/radvirtualgrid/features/pinned-rows-and-columns)
