Telerik blogs

When you first add the RadGridView to your WPF application you will undoubtedly notice the section at the top of the control which I have outlined in red. 


This area is officially called the GridViewGroupPanel, but I am just going to call it the Group Panel to save myself some typing.  The Group Panel allows the user to drag and drop column headers into the panel in order to group the data in the RadGridView at runtime.  Below you will see that I have grouped my data by the "Make" column in my grid of vehicles.


Additionally, the sort order of each grouped column is displayed next in the Group Panel so the user can make changes.  The user is not limited to just a single column either, they can drag several columns into the Group Panel, rearrange the grouping and so forth.  Grouping in this manner gives the user power to control how they want to view the data and reduces the coding burden for the developer.  There are times however when you want to restrict the user from grouping the data, limit grouping to certain columns or better yet setup grouping programmatically. 

If you don't want anyone grouping the data you can remove the Group Panel from the RadGridView by setting the ShowGroupPanel property equal to False.


You also have the ability to tell the Grid not to allow a certain column or columns to be grouped via the Group Panel.  This is done by accessing the GridViewColumnCollection and setting the specific column's IsGroupable property equal to False as demonstrated below.

radGridView1.Columns["Model"].IsGroupable = false

Grouping data programmatically in the RadGridView is done by adding RadGroupDescription objects to the RadGridView's GroupDescription collection.  Provide the column that you want to group by and the preferred sort order and Voila! you have grouped the data programmatically.

radGridView1.GroupDescriptions.Add(new Telerik.Windows.Data.RadGroupDescription("Model", System.ComponentModel.ListSortDirection.Ascending)); 

It is important to note that even though the IsGroupable setting for a column is set to False, they column can still be grouped programmatically.  Additionally, ShowGroupPanel setting does not restrict you from grouping programmatically, as illustrated below. 


The last aspect of grouping data in the RadGridView for WPF I would like to cover is the use of AggregateFunctions.  The RadGroupDescription object that is used to manage grouped data uses the AggregateFunctions collection to allow you to aggregate data.  Data can be aggregated a variety of ways includeing Sum, Average, Min and Max.  See the code below for how to use AggregateFunctions.

var radGroupDescription = new Telerik.Windows.Data.RadGroupDescription("Make", System.ComponentModel.ListSortDirection.Ascending);     
var countFunction = new Telerik.Windows.Data.CountFunction("Make""Make""Number of Vehicles");     
var averageFunction = new Telerik.Windows.Data.AverageFunction("Doors""Doors""Average doors per Vehicle");     

When I run this code you will see that now, in the Group row that the Captions I identified are listed along with the aggregated data.  There are ways to do this inside of your data, but the RadGridView for WPF provides this functionality out of the box.


This should give you a good idea how to group your data effectively with the RadGridView for WPF.


Comments are disabled in preview mode.