# Grouping

**RadListView** supports both custom grouping and automatic grouping based on a certain property.

## Basic Grouping

The basic grouping is achievable by enabling the **EnableGrouping** and **ShowGroups** properties and then adding the desired **GroupDescriptors** to the **GroupDescriptors** collection of the control. The following code will group the items according to their **Value** property:

#### Group by value

```C#
radListView1.EnableGrouping = true;
radListView1.ShowGroups = true;
GroupDescriptor groupByValue = new GroupDescriptor(new SortDescriptor[] { new SortDescriptor("Value", ListSortDirection.Descending) });
radListView1.GroupDescriptors.Add(groupByValue);
```

```VB.NET
RadListView1.EnableGrouping = True
RadListView1.ShowGroups = True
Dim groupByValue As New GroupDescriptor(New SortDescriptor() {New SortDescriptor("Value", ListSortDirection.Descending)})
RadListView1.GroupDescriptors.Add(groupByValue)
```

| Before Grouping                                                                                                                                                            | After Grouping                                                                                                                                                            |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![WinForms RadListView Before Grouping](https://www.telerik.com/products/winforms/documentation/assets/07b480ad11c950cf8ade72dabf58ea08/listview-features-grouping001.png) | ![WinForms RadListView After Grouping](https://www.telerik.com/products/winforms/documentation/assets/cc8ee13041d0e746fb669d5bc77db0d6/listview-features-grouping004.png) |

And here is how you can group by a certain column when **DetailsView** is used:

#### Group by column "Type"

```C#
radListView1.EnableGrouping = true;
radListView1.ShowGroups = true;
GroupDescriptor groupByType = new GroupDescriptor(new SortDescriptor[] 
{
    new SortDescriptor("Type", ListSortDirection.Descending), 
});
radListView1.GroupDescriptors.Add(groupByType);
```

```VB.NET
RadListView1.EnableGrouping = True
RadListView1.ShowGroups = True
Dim groupByType As New GroupDescriptor(New SortDescriptor() {New SortDescriptor("Type", ListSortDirection.Descending)})
RadListView1.GroupDescriptors.Add(groupByType)
```

| Before Grouping                                                                                                                                                   | After Grouping                                                                                                                                                   |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![WinForms RadListView Before](https://www.telerik.com/products/winforms/documentation/assets/b35b061b944ff3c10061ab4220e81092/listview-features-grouping002.png) | ![WinForms RadListView After](https://www.telerik.com/products/winforms/documentation/assets/7d28d3faca9c4a08ef2fd2e162fad275/listview-features-grouping005.png) |

## Custom Grouping

To take advantage of the custom grouping feature of **RadListView**, just enable the **EnableCustomGrouping** property and specify the **Group** for each item. Here is an example for custom grouping:

#### Custom Grouping

```C#
radListView1.EnableCustomGrouping = true;
radListView1.ShowGroups = true;
ListViewDataItemGroup docGroup = new ListViewDataItemGroup("Documents");
ListViewDataItemGroup diskGroup = new ListViewDataItemGroup("Disks");
radListView1.Groups.Add(docGroup);
radListView1.Groups.Add(diskGroup);
foreach (ListViewDataItem item in radListView1.Items)
{
    if (item.Value.ToString() == "Shared Documents" || item.Value.ToString() == "Administrator's Documents")
    {
        item.Group = docGroup;
    }
    else
    {
        item.Group = diskGroup;
    }
}
```

```VB.NET
RadListView1.EnableCustomGrouping = True
RadListView1.ShowGroups = True
Dim docGroup As New ListViewDataItemGroup("Documents")
Dim diskGroup As New ListViewDataItemGroup("Disks")
RadListView1.Groups.Add(docGroup)
RadListView1.Groups.Add(diskGroup)
For Each item As ListViewDataItem In RadListView1.Items
    If item.Value = "Shared Documents" OrElse item.Value = "Administrator's Documents" Then
        item.Group = docGroup
    Else
        item.Group = diskGroup
    End If
Next
```

> important Items in a certain group are sorted in the order of setting the **Group** property of each **ListViewDataItem**.

Please note, that if you are using data binding, you can use the **ItemDataBound** event,  to assign certain item to a certain group.

| Before grouping                                                                                                                                                                   | After grouping                                                                                                                                                                   |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![WinForms RadListView Before Custom Grouping](https://www.telerik.com/products/winforms/documentation/assets/319fbe51742d691500f337d4b0b75c7d/listview-features-grouping003.png) | ![WinForms RadListView After Custom Grouping](https://www.telerik.com/products/winforms/documentation/assets/fcf507708ec9b6219ca813c8600e88cd/listview-features-grouping006.png) |

When grouping is enabled you have the option to quickly expand or collapse all groups in **RadListView** throught the **ExpandAll** and **CollapseAll** methods:

#### Expand and Collapse All Groups

```C#
this.radListView1.ExpandAll();
this.radListView1.CollapseAll();
```

```VB.NET
Me.RadListView1.ExpandAll()
Me.RadListView1.CollapseAll()
```

## See Also

* [Filtering](https://www.telerik.com/products/winforms/documentation/controls/listview/features/filtering)
* [Sorting](https://www.telerik.com/products/winforms/documentation/controls/listview/features/sorting)
* [Move ListView Items Between Groups in Unbound Mode](https://www.telerik.com/products/winforms/documentation/knowledge-base/move-listview-items-between-groups-in-unbound-mode)
