Within a DataGrid control, a selection can be made by a click/tap on a cell/row, which raises the SelectionChanged event.
You can listen to the CollectionChanged event of the SelectedItem directly.
You can unselect by a click/tap on the already selected cell/row.
RadDataGrid supports different selection modes that can be modified by the following properties:
First, you can choose the Unit that you will be allowed to select and then the Selection Mode.
To define a Cell when using a selection you can use the DataGridCellInfo class, that holds all the information about it.
To define a Row when using a selection you can use your data object.
Once you make a selection, you can get or modify a collection with the selected Items by using:
SelectedItems property (type of ObservableCollection<object>):
- Gets or Modifies an ObservableCollection of the currently selected Items(their type depends on the applied SelectionUnit, that is, DataGridCellInfo for Cell and Data Item for Row).
Additional functionalities for programmatic selecting and deselecting items are exposed by this component as methods. They also depend on the applied SelectionUnit.
- Selects the specified data item and adds it in the SelectedItems collection.
- Removes the selection for the specified data item and removes it from the SelectedItems collection.
- Selects the grid cell as defined by the specified cell info.
- Removes the selection for the grid cell defined by the specified cell info.
- Selects all the items as defined by the SelectionMode and SelectionUnit property.
- Clears the current selected items as defined by the SelectionUnit property.