# Grouping Support

RadPropertyGrid supports grouping. Its **IsGrouped** property controls the current RadPropertyGrid's state. You can set it to **true** and you will have RadPropertyGrid **initially grouped**. If you set it to **false**, then you will have RadProperty **sorted**. By default the control is shown as sorted.

> Please note all the groups will be auto expanded. In case you want to initially collapse a group, you can do this once RadPropertyGrid is loaded using a Dispatcher. Please refer to the [Expand/Collapse Groups](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/grouping#expand-collapse-groups) section below.

Another property you can configure is **SortAndGroupButtonsVisibility**. It sets the visibility mode of the sort and group buttons. By default the buttons will be visible.

For example, lets have the following declaration of the RadPropertyGrid control:

**Example 1: Declaring RadPropertyGrid**

```XAML
<telerik:RadPropertyGrid Grid.Row="0" x:Name="PropertyGrid1"
	                          RenderMode="Flat"
	                          AutoGeneratePropertyDefinitions="False"
	                          IsGrouped="True">
    <telerik:RadPropertyGrid.PropertyDefinitions>
        <telerik:PropertyDefinition Binding="{Binding FirstName}" GroupName="Group Name" DisplayName="First Name"/>
        <telerik:PropertyDefinition Binding="{Binding LastName}" GroupName="Group Name" DisplayName="Last Name"/>
        <telerik:PropertyDefinition Binding="{Binding Title}" GroupName="Group Title" DisplayName="Title"/>
        <telerik:PropertyDefinition Binding="{Binding HomePhone}" GroupName="Group Phone" DisplayName="HomePhone"/>
    </telerik:RadPropertyGrid.PropertyDefinitions>
</telerik:RadPropertyGrid>
```

Its Item is set like so:

**Example 2: Setting RadPropertyGrid Item**

```C#
Employee employee = new Employee()
{
    FirstName = "Nancy",
    LastName = "Davolio",
    Title = "Sales Representative",
    HomePhone = "(206) 555-9857"
};
this.PropertyGrid1.Item = employee;
```

```VB.NET
	Dim Employee As New Employee() With {
	    .FirstName = "Nancy",
	    .LastName = "Davolio",
	    .Title = "Sales Representative",
	    .HomePhone = "(206) 555-9857"
	}
	Me.PropertyGrid1.Item = Employee
```

Now, if you run your application, you will see this result:

![Rad Property Grid Grouping](https://www.telerik.com/products/wpf/documentation/assets/c2b0c24a47e23384c0146d15be2f3bf4/radpropertygrid_grouping.png)

## Expand/Collapse Groups

The user can control the group state from the UI.

He can also collapse and expand groups in RadPropertyGrid in code using its methods:

* **ExpandGroup(object GroupKey)**: Sets expand state for the given GroupDefinition

**Example 3: Expanding RadPropertyGrid Group**

```C#
this.PropertyGrid1.ExpandGroup("Group Name");
```

```VB.NET
	Me.PropertyGrid1.ExpandGroup("Group Name")
```

* **CollapseGroup(object GroupKey)**: Collapses the visual group for the given GroupDefinition

**Example 4: Collapsing RadPropertyGrid Group**

```C#
this.PropertyGrid1.CollapseGroup("Group Name");
```

```VB.NET
	Me.PropertyGrid1.CollapseGroup("Group Name")
```

* **ExpandAllGroups()**: Expands all groups recursively

**Example 5: Expanding all RadPropertyGrid Groups**

```C#
this.PropertyGrid1.ExpandAllGroups();
```

```VB.NET
	Me.PropertyGrid1.ExpandAllGroups()
```

* **CollapseAllGroups()**: Collapses all groups recursively.

**Example 6: Collapsing all RadPropertyGrid Groups**

```C#
this.PropertyGrid1.CollapseAllGroups();
```

```VB.NET
	Me.PropertyGrid1.CollapseAllGroups()
```

> important You need to set **RenderMode="Flat"** in order to be able to execute the methods above. For more information check [Layout Rendering Modes](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/layout-rendering-modes).

## GroupDefinitions

The GroupDefinitions property gets a collection of GroupDefinition objects used to group RadPropertyGrid.

It has two methods:

* **SuspendNotifications()**: Suspends the notifications.

* **ResumeNotifications()**: Resumes the notifications.

**Example 7: Suspending and Resuming notifications**

```C#
this.PropertyGrid1.GroupDefinitions.SuspendNotifications();
// Execute additional logic
this.PropertyGrid1.GroupDefinitions.ResumeNotifications();
```

```VB.NET
	Me.PropertyGrid1.GroupDefinitions.SuspendNotifications()
	' Execute additional logic
	Me.PropertyGrid1.GroupDefinitions.ResumeNotifications()
```

> important You need to set **RenderMode="Flat"** in order to be able to work with the GroupDefinitions collection. For more information check [Layout Rendering Modes](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/layout-rendering-modes).

## AutoExpandGroups

As of **R2 2019**, the RadPropertyGrid control exposes a new boolean property - **AutoExpandGroups**. It controls whether groups should be expanded or not when loaded. The default value is **True** meaning that all groups are initially expanded.

**Example 8: Set groups' initial state to collapsed**

```C#
this.PropertyGrid1.AutoExpandGroups = false;
```

```VB.NET
	this.PropertyGrid1.AutoExpandGroups = False
```

## See Also

* [Getting Started with RadPropertyGrid](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/getting-started/getting-started)

* [Edit Modes](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/edit-modes)

* [Scrolling into View](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/scrolling)

* [Customizing Groups Appearance](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/customizing-groups-appearance)
