# Grouping

RadCardView supports grouping via the UI or in code, in case you are using ICollectionView as the ItemsSource.

> caption RadCardView groups

![WPF RadCardView RadCardView groups](https://www.telerik.com/products/wpf/documentation/assets/d2ffd8fc1ef610eab1e01e77854a0837/radcardview-features-grouping-0.png)

The control internally works with a [QueryableCollectionView](https://www.telerik.com/products/wpf/documentation/common-information/consuming-data/queryablecollectionview) instance. If you set the ItemsSource of the RadCardView that is not a QueryableCollectionView, then the original collection is wrapped in a QueryableCollectionView instance. This way grouping is supported even if you use a more basic IEnumerable implementation, like `List<T>` or `ObservableCollection<T>`.

## Grouping in the UI

The data items can be grouped by dragging a data field descriptor from the [data field descriptors list](https://www.telerik.com/products/wpf/documentation/controls/radcardview/visual-structure) to the group panel area.

> caption Dragging data field descriptor

![WPF RadCardView Dragging data field descriptor](https://www.telerik.com/products/wpf/documentation/assets/e59cf6511e325c0e7f3527b7aa022589/radcardview-features-grouping-1.png)

> caption Grouped RadCardView

![WPF RadCardView Grouped RadCardView](https://www.telerik.com/products/wpf/documentation/assets/d2ffd8fc1ef610eab1e01e77854a0837/radcardview-features-grouping-0.png)

The RadCardView groups support sorting by clicking onto the associated [group member button](https://www.telerik.com/products/wpf/documentation/controls/radcardview/visual-structure). To disable this, set the **CanUserSortGroups** property to **False**.

**Example 1: Setting the CanUserSortGroups property**

```XAML
<telerik:RadCardView CanUserSortGroups="False" />
```

Additionally, the grouping can be disabled per [CardDataFieldDescriptor](https://www.telerik.com/products/wpf/documentation/controls/radcardview/features/datafielddescriptors) by setting its **AllowGrouping** property.

## Programmatic Grouping

The following example shows how to setup RadCardView, populate it a [QueryableCollectionView](https://www.telerik.com/products/wpf/documentation/common-information/consuming-data/queryablecollectionview) and add GroupDescriptors in code.

**Example 2: Defining the model**

```C#
public class CardInfo
{
    public string Header { get; set; }
    public string Name { get; set; }
    public int Number { get; set; }
    public string Category { get; set; }
}

public class MainViewModel
{
    public ObservableCollection<CardInfo> Items { get; private set; }
    public QueryableCollectionView CollectionView { get; private set; }

    public MainViewModel()
    {
        int counter = 0;
        Items = new ObservableCollection<CardInfo>();
        for (int g = 0; g < 3; g++)
        {
            for (int i = 0; i < 6; i++)
            {
                Items.Add(new CardInfo()
                {
                    Header = "Card " + counter,
                    Name = "Name " + counter,
                    Number = counter,
                    Category = "Category " + g
                });
                counter++;
            }
        }

        CollectionView = new QueryableCollectionView(Items);
        CollectionView.GroupDescriptors.Add(new GroupDescriptor() { Member = "Category" });
    }
}
```

> tip Read the [QueryableCollectionView](https://www.telerik.com/products/wpf/documentation/common-information/consuming-data/queryablecollectionview#grouping) to see how to use the GroupDescriptors collection of the QueryableCollectionView.

**Example 3: Setting the DataContext**

```C#
public FeaturesGroupingWindow()
{
    InitializeComponent();
    this.DataContext = new MainViewModel();
}
```

**Example 4: Setting up the view**

```XAML
<telerik:RadCardView ItemsSource="{Binding CollectionView}" CardHeaderBinding="{Binding Header}" />
```

## Events

The grouping operations invoke several events that can be used to customize the grouping. Read more in the [Events](https://www.telerik.com/products/wpf/documentation/controls/radcardview/events#grouping) article.

## Customizing Grouping UI

The [group panel area](https://www.telerik.com/products/wpf/documentation/controls/radcardview/visual-structure) can be customized using several public properties. To hide the area, set the **ShowGroupPanel** property to **False**. Read more in the [Customizing Groups](https://www.telerik.com/products/wpf/documentation/controls/radcardview/appearance/customizing-groups) article.

**Example 5: Setting the ShowGroupPanel property**

```XAML
<telerik:RadCardView ShowGroupPanel="False" />
```

## See Also

* [Getting Started](https://www.telerik.com/products/wpf/documentation/controls/radcardview/getting-started)
* [Data Binding](https://www.telerik.com/products/wpf/documentation/controls/radcardview/populating-with-data/data-binding)
* [Filtering](https://www.telerik.com/products/wpf/documentation/controls/radcardview/features/filtering)
* [Sorting](https://www.telerik.com/products/wpf/documentation/controls/radcardview/features/sorting)
