Selection
PropertyGrid has a selection functionality, which allows the user to select one or more items from the data displayed by the control.
Selection Modes
PropertyGrid has three selection modes - single, multiple and extended. The default mode is Single
and can be changed via the SelectionMode
property RadPropertyGrid
which has the following entries:
Single
(default value)—Only one item can be selected at a time.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 theCtrl
orShift
key.
Setting the SelectionMode
<telerikControls:RadPropertyGrid SelectionMode="Multiple" />
Pressing
Ctrl+A
will select all items when the selection mode isMultiple
orExtended
.
Disabling User Selection
To disable the selection on click, set the CanUserSelect
property of RadPropertyGrid
to False
.
Disable user selection
<telerikControls:RadPropertyGrid CanUserSelect="False"/>
Accessing Selected Items
The selected items can be accessed using the SelectedPropertyDefinition
and SelectedPropertyDefinitions
properties of RadPropertyGrid
. You can use these properties to get or set items of type PropertyDefinition
, which are used to described the displayed properties.
Getting the current selection
<telerikControls:RadPropertyGrid SelectionMode="Multiple" />
Setting the selection using the SelectedPropertyDefinition
this.propertyGrid.SelectedPropertyDefinition = this.properties.PropertyDefinitions[2];
Setting the selection with SelectedPropertyDefinition binding
<telerikControls:RadPropertyGrid SelectedPropertyDefinition="{Binding MySelectedDefinitionProperty, Mode=TwoWay}" />
Setting the selection using the SelectedPropertyDefinitions
this.propertyGrid.SelectedPropertyDefinitions.Add(this.properties.PropertyDefinitions[2]);
SelectionChanged Event
The SelectionChanged
event of RadPropertyGrid
is raised each time the selection is modified.
SelectionChanged event handler
private void RadPropertyGrid_SelectionChanged(object sender, Telerik.UI.Xaml.SelectionChangedEventArgs e)
{
IList selectedItems = e.AddedItems;
IList unselectedItems = e.RemovedItems;
}