Skip to main content
A newer version of this page is available. .

How to: Create Group Summaries

The following example shows how to create two group summary items. The first summary item will represent the number of records within groups, and will be displayed in group rows. The second item will calculate the sum of values against the UnitPrice field, and will be displayed under the Unit Price column within group footers. The result of the code execution is presented below:

Summary-GroupCodeResult

using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;

// Make the group footers always visible.
gridView1.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways;
// Create and setup the first summary item.
GridGroupSummaryItem item = new GridGroupSummaryItem();
item.FieldName = "ProductName";
item.SummaryType = DevExpress.Data.SummaryItemType.Count;         
gridView1.GroupSummary.Add(item);
// Create and setup the second summary item.
GridGroupSummaryItem item1 = new GridGroupSummaryItem();
item1.FieldName = "UnitPrice";
item1.SummaryType = DevExpress.Data.SummaryItemType.Sum;
item1.DisplayFormat = "Total {0:c2}";
item1.ShowInGroupColumnFooter = gridView1.Columns["UnitPrice"];
gridView1.GroupSummary.Add(item1);