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

Custom Grouping

Custom grouping is a flexible mechanism for creating RadPropertyGrid groups by using custom logic. It has a higher priority than the applied GroupDescriptors. Grouping is applied if user grouping is enabled through the RadPropertyGrid.EnableGrouping or PropertyGridElement.EnableGrouping properties. By default, grouping is enabled.

You can use the ItemFormatting event to format the group text of the created custom groups.

Using the CustomGrouping Event

The CustomGrouping event is fired if custom grouping is enabled through the RadPropertyGrid.EnableCustomGrouping or PropertyGridElement.EnableCustomGrouping properties. By default, custom grouping is disabled.

  • PropertyGridTable: The table while holds the items that will be grouped

  • Item: The item which group is defined

  • GroupKey: Identifier of the group

  • Handled: Defines whether the item is processed by the custom algorithm or by the applied group descriptors.

The following example demonstrates how to handle the CustomGrouping event to group the RadPropertyGrid items by the type of the property:

Figure 1: Custom Grouping

WinForms RadPropertyGrid Custom Grouping

Custom Grouping

public PropertyGridCustomGrouping()
    radPropertyGrid1.SelectedObject = new RadButton();
    radPropertyGrid1.ToolbarVisible = true;
    this.radPropertyGrid1.EnableCustomGrouping = true;
    this.radPropertyGrid1.CustomGrouping += new PropertyGridCustomGroupingEventHandler(radPropertyGrid1_CustomGrouping);
    radPropertyGrid1.ItemFormatting += new PropertyGridItemFormattingEventHandler(radPropertyGrid1_ItemFormatting);
    GroupDescriptor descriptor = new GroupDescriptor("PropertyType");
void radPropertyGrid1_ItemFormatting(object sender, PropertyGridItemFormattingEventArgs e)
    PropertyGridGroupItem groupItem = e.Item as PropertyGridGroupItem;
    if (groupItem != null)
        e.Item.Label = groupItem.Group.Key.ToString();
private void radPropertyGrid1_CustomGrouping(object sender, PropertyGridCustomGroupingEventArgs e)
    Type propertyType = e.Item.PropertyType;
    if (propertyType.IsClass)
        e.GroupKey = "Reference type";
        e.GroupKey = "Value type";

Public Sub New()
    RadPropertyGrid1.SelectedObject = New RadButton()
    RadPropertyGrid1.ToolbarVisible = True
    Me.RadPropertyGrid1.EnableCustomGrouping = True
    Dim descriptor As New GroupDescriptor("PropertyType")
End Sub
Private Sub RadPropertyGrid1_CustomGrouping(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.PropertyGridCustomGroupingEventArgs) Handles RadPropertyGrid1.CustomGrouping
    Dim propertyType As Type = e.Item.PropertyType
    If propertyType.IsClass Then
        e.GroupKey = "Reference type"
        e.GroupKey = "Value type"
    End If
End Sub
Private Sub RadPropertyGrid1_ItemFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.PropertyGridItemFormattingEventArgs) Handles RadPropertyGrid1.ItemFormatting
    Dim groupItem As PropertyGridGroupItem = TryCast(e.Item, PropertyGridGroupItem)
    If groupItem IsNot Nothing Then
        e.Item.Label = groupItem.Group.Key.ToString()
    End If
End Sub

See Also

In this article