# Setting Groups Programmatically

## Overview

**RadGridView** has a **GroupDescriptors** property at the **GridViewTemplate** level which is exposed in **RadGridView** class for **MasterTemplate** instance. This collection allows you to use descriptors which define the grouping criteria and the group's sorting direction for the data that is bound to the **RadGridView**.

As this is a collection, you are able not only to add, but to remove or clear its entries as well. Adding descriptors to the collection makes the current view display the items sorted and divided into groups.

## Using GroupDescriptors

#### Using simple group descriptor

```C#
GroupDescriptor descriptor = new GroupDescriptor();
descriptor.GroupNames.Add("Country", ListSortDirection.Ascending);
this.radGridView1.GroupDescriptors.Add(descriptor);
```

```VB.NET
Dim descriptor As New GroupDescriptor()
descriptor.GroupNames.Add("Country", ListSortDirection.Ascending)
Me.RadGridView1.GroupDescriptors.Add(descriptor)
```

**Grid grouped by a simple group descriptor**

![Telerik UI for WinForms RadGridView showing data grouped by a single GroupDescriptor](https://www.telerik.com/products/winforms/documentation/assets/b037588d4a14521442c59fa6386b0560/gridview-grouping-setting-groups-programmatically001.png)

The **GroupNames** property defines the property, by which the data will be grouped. The **GroupNames** is a **SortDescriptorCollection** and defines group names for one grouping criteria.

**RadGridView** supports grouping using one or more property names. The following example demonstrates how you can group by two properties:

#### Grouping by more than one column name

```C#
GroupDescriptor descriptor1 = new GroupDescriptor();
descriptor1.GroupNames.Add("Country", ListSortDirection.Ascending);
descriptor1.GroupNames.Add("ContactTitle", ListSortDirection.Descending);
this.radGridView1.GroupDescriptors.Add(descriptor1);
```

```VB.NET
Dim descriptor1 As New GroupDescriptor()
descriptor1.GroupNames.Add("Country", ListSortDirection.Ascending)
descriptor1.GroupNames.Add("ContactTitle", ListSortDirection.Descending)
Me.RadGridView1.GroupDescriptors.Add(descriptor1)
```

**Grid grouped by more than one column name**

![Telerik UI for WinForms RadGridView showing grouping by multiple column names within the same group descriptor](https://www.telerik.com/products/winforms/documentation/assets/dd8be7fddd024d5f27d95c17e4801d9d/gridview-grouping-setting-groups-programmatically002.png)

**RadGridView** supports grouping on one or more levels. The following example demonstrates how you can group on two levels:

#### Grouping on one or more levels

```C#
GroupDescriptor descriptor2 = new GroupDescriptor();
descriptor2.GroupNames.Add("Country", ListSortDirection.Ascending);
GroupDescriptor descriptor3 = new GroupDescriptor();
descriptor3.GroupNames.Add("ContactTitle", ListSortDirection.Ascending);
this.radGridView1.GroupDescriptors.Add(descriptor2);
this.radGridView1.GroupDescriptors.Add(descriptor3);
```

```VB.NET
Dim descriptor2 As New GroupDescriptor()
descriptor2.GroupNames.Add("Country", ListSortDirection.Ascending)
Dim descriptor3 As New GroupDescriptor()
descriptor3.GroupNames.Add("ContactTitle", ListSortDirection.Ascending)
Me.RadGridView1.GroupDescriptors.Add(descriptor2)
Me.RadGridView1.GroupDescriptors.Add(descriptor3)
```

**Grid grouped across multiple hierarchy levels**

![Telerik UI for WinForms RadGridView showing grouping applied across multiple hierarchy levels](https://www.telerik.com/products/winforms/documentation/assets/558b3a8c794b22c4d0626ead49001110/gridview-grouping-setting-groups-programmatically003.png)

## See Also

* [Basic Grouping](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/basic-grouping)

* [Custom Grouping](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/custom-grouping)

* [Events](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/events)

* [Formatting Group Header Row](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/formatting-group-header-row)

* [Group Aggregates](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/group-aggregates)

* [Groups Collection](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/groups-collection)

* [Sorting group rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/sorting-group-rows)

* [Using Grouping Expressions](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/using-grouping-expressions)
