New to Telerik UI for WinForms? Start a free 30-day trial
Group Aggregates
Updated over 6 months ago
The text of the group header row is a formatted string with the following parameters:
-
{0} – Property name –the name of the RadGridView column by which the grouping is performed;
-
{1} – Group value
-
{2}, {3} … - Aggregates values
You can define the format of the group header row by using the GroupDescriptor Format property. Its default value is “{0}: {1}”. The following two examples demonstrate how you can use the group aggregates. Full list of the available expressions can be found here:http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx
Example 1: Adding the Count Aggregate
C#
GroupDescriptor descriptor = new GroupDescriptor();
descriptor.GroupNames.Add("Country", ListSortDirection.Ascending);
descriptor.Aggregates.Add("Count(Country)");
descriptor.Format = "{0}: {1} has {2} records in its group.";
this.radGridView1.GroupDescriptors.Add(descriptor);

Example 2: Adding and Formatting Several Aggregates
C#
GroupDescriptor descriptor = new GroupDescriptor();
descriptor.GroupNames.Add("ShipName", ListSortDirection.Ascending);
descriptor.Aggregates.Add("Count(ShipName)");
descriptor.Aggregates.Add("Max(Freight)");
descriptor.Aggregates.Add("Avg(Freight)");
descriptor.Format = "The ship {1} has {2} item(s) with maximum freight {3} and average freight of {4:c2} per ship.";
this.radGridView1.GroupDescriptors.Add(descriptor);
