下面的示例展示了如何创建两个分组汇总项。 第一个汇总项表示分组内记录的总数,并显示在分组行中。 第二个汇总项计算 UnitPrice 字段的合计,并显示在分组脚注内、 Unit Price 列下面。 代码的运行结果如下图所示:

C#CopyCode image复制代码
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 = colUnitPrice;
gridView1.GroupSummary.Add(item1);
Visual BasicCopyCode image复制代码
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid

' Make the group footers always visible.
Private gridView1.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways
' Create and setup the first summary item.
Private item As GridGroupSummaryItem = New GridGroupSummaryItem()
Private item.FieldName = "ProductName"
Private item.SummaryType = DevExpress.Data.SummaryItemType.Count
gridView1.GroupSummary.Add(item)
' Create and setup the second summary item.
Dim item1 As GridGroupSummaryItem = New GridGroupSummaryItem()
item1.FieldName = "UnitPrice"
item1.SummaryType = DevExpress.Data.SummaryItemType.Sum
item1.DisplayFormat = "Total {0:c2}"
item1.ShowInGroupColumnFooter = colUnitPrice
gridView1.GroupSummary.Add(item1)