RadGridView provides you with selection functionality, which allows the user to select one or more rows and/or cells from the data displayed by the control.
The selection mechanism can be controlled programmatically too. For more information take a look at the Programmatic Selection article.
Users can select an item in through the control's UI by clicking somewhere on the desired row.
Figure 1: Row Selection
If enabled, users can also select a single cell or multiple cells as shown in Figure 2.
Figure 2: Cell Selection
To set the selection unit, use the SelectionUnit enumeration property of the RadGridView. Setting it to FullRow will enable the selection of rows (default) while setting it to Cell will enable the cell selection.
The RadGridView control provides three selection modes, which allow you to manipulate the type of selection. This is controlled by the SelectionMode enumeration property which has the following values:
Single: Only one item can be selected at a time. (default value)
Multiple: Items are added to the selection when they get clicked and get removed when they get clicked again.
Extended: Items are added to the selection only by combining the mouse clicks with the Ctrl or Shift keys.
To learn more about the multiple selections (the Multiple and Extended selection modes) take a look at the Multiple Selection topic.
RadGridView also provides three selection units, which allow you to manipulate what units are selected when you interact with the grid. This is controlled by the SelectionUnit enumeration property which has the following values:
FullRow: This is the default value. Clicking within the cells will select the whole row.
- Cell: Only te clicked cell is selected. Depending on the value of the SelectionModes property you can have more than one selected cell.
- Mixed: You can select both cells and rows. To select a row you should click either on the row indicator or outside any cells in the row.
RadGridView provides several properties to get the data behind the selected items - SelectedItem, SelectedItems and SelectedCells.
- SelectedItem: The business object corresponding to the selected row. If the SelectionUnit is Cell or no full rows have been selected, it's value is null.
- SelectedItems: A collection of the business objects corresponding to the selected rows. If the SelectionUnit is Cell or no full rows have been selected, the collection is empty.
- SelectedCells: A collection of GridViewCellInfo objects which represent the corresponding business object(s) and the column(s) of the selected cell(s).
When filtering is applied to the control, if a currently selected item does not pass the filtering criteria, it will be deselected.
To disable the selection functionality you can set the CanUserSelect property to False.
This will only disable the selection. The user will still be able to change the current item.
This will disable the selection for only the end-user. It still will be possible to manipulate the selection programmatically.
Example 1: Set the CanUserSelect property in XAML
<telerik:RadGridView x:Name="radGridView" CanUserSelect="False"> </telerik:RadGridView>
Example 1: Set the CanUserSelect property in code-behind
this.radGridView.CanUserSelect = false;
Me.radGridView.CanUserSelect = False
When the SelectionMode is Extended, you can set the DragElementAction property of the RadGridView in order to specify the action that will be taken when the user performs a drag over the GridViewRows. This property is of type DragAction and has the following values:
- ExtendedSelect: Performs selection without taking the drag unit selection state.
- None: Does not execute any action. This is the default value.
- Select: Performs selection. This mode does not perform selection when dragging from a unit that is selected.
There are five events relevant to the selection functionality in the RadGridView - SelectionChanging, SelectionChanged, CurrentCellChanged, SelectedCellsChanging and SelectedCellsChanged. To learn more about each of them go to the Selection Events article.