windowsforms-devexpress-dot-xtragrid-98391da5.md
Represents an individual group summary item.
Namespace : DevExpress.XtraGrid
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
public class GridGroupSummaryItem :
GridSummaryItem
Public Class GridGroupSummaryItem
Inherits GridSummaryItem
The following members return GridGroupSummaryItem objects:
Grid Views provide the GridView.GroupSummary property which is a collection of group summary items. Each group summary item is represented by a GridGroupSummaryItem object. Such objects provide settings that specify the aggregation function type, the field whose values are used to calculate the function value and the summary value formatting. Aggregate function values are calculated for each group of rows. Formatted results are displayed either within group rows or group footers under the specified column. Please refer to the Summaries topic for additional information.
The GridGroupSummaryItem class inherits members affecting summary item customization from the GridSummaryItem class that is used to represent total summary items. The GridGroupSummaryItem.ShowInGroupColumnFooter property introduced specifies the summary value position. If set to a column, summary values will be displayed within row footer cells under the specified column. If set to null ( Nothing in Visual Basic), summary values will be displayed within group rows.
To create group summaries at runtime, you need to create GridGroupSummaryItem objects, customize them as needed and add them to the GridView.GroupSummary collection.
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:
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
public MyForm() {
InitializeComponent();
this.Load += OnFormLoad;
}
private void OnFormLoad(object sender, EventArgs e) {
bandedGridView1.Columns["Discontinued"].Group();
CreateGroupSummaries();
}
private void CreateGroupSummaries() {
// Make the group footers always visible.
bandedGridView1.OptionsView.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways;
// Create and setup the first summary item.
GridGroupSummaryItem item = new GridGroupSummaryItem();
item.FieldName = "ProductName";
item.SummaryType = DevExpress.Data.SummaryItemType.Count;
bandedGridView1.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 = bandedGridView1.Columns["UnitPrice"];
bandedGridView1.GroupSummary.Add(item1);
}
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid
Public Sub New()
InitializeComponent()
AddHandler Me.Load, AddressOf OnFormLoad
End Sub
Private Sub ExcelFiltering_Load(ByVal sender As Object, ByVal e As EventArgs)
bandedGridView1.Columns("Discontinued").Group()
CreateGroupSummaries()
End Sub
private void CreateGroupSummaries() {
// Make the group footers always visible.
bandedGridView1.OptionsView.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways;
// Create and setup the first summary item.
GridGroupSummaryItem item = new GridGroupSummaryItem();
item.FieldName = "ProductName";
item.SummaryType = DevExpress.Data.SummaryItemType.Count;
bandedGridView1.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 = bandedGridView1.Columns["UnitPrice"];
bandedGridView1.GroupSummary.Add(item1);
}
Object GridSummaryItem GridGroupSummaryItem
See Also