The RadGridView provides you with a selection functionality, which allows the user to select one or more items 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 topic.|
To select an item in the RadGridView click somewhere on the desired row.
As of Q2 2010, you can also select a single cell or individual cells as opposed to selecting the full row:
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 provides three selection modes, which allow you to manipulate the type of selection. This is controlled by the SelectionMode enumeration property which have the following entries:
- 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 key.
|To learn more about the multiple selection (Multiple and Extended selection modes) take a look at the Multiple Selection topic.|
The RadGridView 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 have the following entries:
- FullRow - this is the default value. Clicking within the cells will select the row
- Cell - the clicked cell is selected only. Depending on the value of the SelectionModes property you can have more than one selected cell.
- Mixed - you can select any cell and you can as well select a full row if you click on a row, but not on a cell from it.
|The Mixed state is added with Q3 SP 2012 release|
The SelectionUnit property is added in Q2 2010 release.
RadGridView provides several properties to get the data behind the selected items - SelectedItem, SelectedItems and SelectedCells.
- SelectedItem - the business object that sits behind the selected row. You can use it when the SelectionUnit is set to FullRow (default), otherwise it is null.
- SelectedItems - a collection of the business objects that sit behind the selected rows. You can use it when the SelectionUnit is set to FullRow (default), otherwise it is null. It will contain more than one item when the SelectionMode is either Multiple or Extended.
- SelectedCells - a collection of GridViewCellInfo objects which represent the business object and the column of the selected cell/cells. You can use it when the SelectionUnit is set to Cell, otherwise it is null.
To disable the selection functionality you can set the CanUserSelect to false.
This will only disable the selection. The user will still be able to change the current item.
This will disable only the selection for the end-user. It still will be possible to manipulate the selection programmatically. To learn more take a look at the Programmatic Selection topic.
If you would like to bind the SelectedItems collection of the RadGridView to a property in the ViewModel, then you could check this
this.radGridView.CanUserSelect = false;
Me.radGridView.CanUserSelect = False
There are five events relevant to the selection in the RadGridView: SelectionChanging,SelectionChanged,CurrentCellChanged, SelectedCellsChanging and SelectedCellChanged. The sequence of the events depends on the SelectionUnit property:
- FullRow - the SelectionChanged is fired first and after that the CurrentCellChanged event fires.
- Cell - the SelectedCellChanged is fired first and after that the CurrentCellChanged event fires
Mixed - you can select any cell and you can as well select a full row if you click on a row, but not on a cell.
|Added with Q3 SP 2012 release|
To learn more about the selection events go to this help topic.