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

DelegateGroupDescriptor

The difference between the DelegateGroupDescriptor and the PropertyGroupDescriptor is that DelegateGroupDescriptor groups data by a custom key, while the PropertyGroupDescriptor groups by a defined key which is a property from our model.

Adding a DelegateGroupDescriptor

To use a DelegateSortDescriptor, you have to create a class that implements the IKeyLookup interface which will return the key you want to group by. Then you need to add the DelegateGroupDescriptor to the GroupDescriptors collection and set its KeyLookUp property as shown in Example 1.

Example 1: Defining the RadDataGrid in xaml

<Grid xmlns:grid="using:Telerik.UI.Xaml.Controls.Grid" 
      xmlns:dataCore="using:Telerik.Data.Core"> 
    <grid:RadDataGrid Width="600" Height="460" x:Name="grid"> 
        <grid:RadDataGrid.GroupDescriptors> 
            <dataCore:DelegateGroupDescriptor> 
                <dataCore:DelegateGroupDescriptor.KeyLookup> 
                    <local:CustomIKeyLookup/> 
                </dataCore:DelegateGroupDescriptor.KeyLookup> 
            </dataCore:DelegateGroupDescriptor> 
        </grid:RadDataGrid.GroupDescriptors> 
    </grid:RadDataGrid> 
</Grid> 

The RadDataGrid is populated with data in the same manner as in Example 2 from the PropertyGroupDescriptor article.

Example 2 demonstrates the implementation of the IKeyLookup interface. The GetKey method will receive an instance of our custom object. In this case we will group the grid items by the first letter of a city.

Example 2: Defining the CustomIKeyLookup class

public class CustomIKeyLookup : IKeyLookup 
{ 
    public object GetKey(object instance) 
    { 
        return (instance as Data).City[0]; 
    } 
} 

Figure 1: Grouped RadDataGrid

Delegate Group Descriptor

See Also

In this article
Not finding the help you need?