New to Telerik UI for WPF? Download free 30-day trial

Selection

RadPropertyGrid provides you with a selection functionality, which allows the user to select one or more items from the data displayed by the control.

Selection Modes

RadPropertyGrid 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 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.

Example 1: Setting the SelectionMode to Multiple

 <telerik:RadPropertyGrid x:Name="propertyGrid" 
                          SelectionMode="Multiple" 
                          RenderMode="Flat" /> 

Example 2: Setting the SelectionMode to Multiple

this.propertyGrid.SelectionMode = System.Windows.Controls.SelectionMode.Multiple; 
Me.propertyGrid.SelectionMode = System.Windows.Controls.SelectionMode.Multiple 

Pressing Ctrl+A will select all items.

Selected items

RadPropertyGrid provides two properties to get the data behind the selected items - SelectedPropertyDefinition and SelectedPropertyDefinitions.

  • SelectedPropertyDefinition: The business object that sits behind the selected Property Definition.

  • SelectedPropertyDefinitions: A collection of the business objects that sits behind the selected Property Definitions. It will contain more than one item when the SelectionMode is either Multiple or Extended.

Example 3: Binding to SelectedPropertyDefinition

 <telerik:RadPropertyGrid x:Name="propertyGrid" 
                          RenderMode="Flat"            
                          SelectedPropertyDefinition="{Binding SelectedDefinition, Mode=TwoWay}" /> 

Example 4: The viewmodel's SelectedDefinition property

public class ViewModel : ViewModelBase 
{ 
    private object selectedDefinition; 
 
    public object SelectedDefinition 
    { 
        get { return selectedDefinition; } 
        set 
        { 
            if (value != this.selectedDefinition) 
            { 
                this.selectedDefinition = value; 
                this.OnPropertyChanged("SelectedDefinition"); 
            } 
        } 
    } 
} 
Public Class ViewModel 
Inherits ViewModelBase 
 
    Private _selectedDefinition As Object 
 
    Public Property SelectedDefinition() As Object 
        Get 
            Return _selectedDefinition 
        End Get 
        Set(ByVal value As Object) 
            If value IsNot Me._selectedDefinition Then 
                Me._selectedDefinition = value 
                Me.OnPropertyChanged("SelectedDefinition") 
            End If 
        End Set 
    End Property 

End Class

As of R2 2016, the SelectedField property, previously marked as obsolete, has officially been removed.

Events

There is a single event relevant to the selection in RadPropertyGrid - SelectionChanged. As suggested by its name, it occurs when the selected property definition has changed.

Example 5: Adding a handler for the SelectionChanged event

<telerik:RadPropertyGrid x:Name="propertyGrid" 
                         RenderMode="Flat" 
                         SelectionChanged="propertyGrid_SelectionChanged"> 

Example 6: SelectionChanged event handler

private void propertyGrid_SelectionChanged(object sender, SelectionChangeEventArgs e) 
{ 
    var propertyDefinition = e.AddedItems[0] as PropertyDefinition; 
    MessageBox.Show($"You selected property definition with DisplayName: {propertyDefinition.DisplayName}"); 
} 
Private Sub propertyGrid_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangeEventArgs) 
    Dim propertyDefinition = TryCast(e.AddedItems(0), PropertyDefinition) 
    MessageBox.Show($"You selected property definition with DisplayName: {propertyDefinition.DisplayName}") 
End Sub 

As of R2 2016, the SelectedFieldChanged event, previously marked as obsolete, has officially been removed.

In this article