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

Summaries

  • 5 minutes to read

Summaries are grid items that utilize aggregate functions to display summary information about displayed data: total record count, minimum values, etc.

Watch Video

Summary Types

Total summaries (GridSummaryItem) are calculated over all Data Grid records and displayed within the view footer. Enable the View’s OptionsView.ShowFooter setting to display the view footer.

Group summaries (GridGroupSummaryItem) are calculated over individual groups and displayed either in a group footer area or within group rows.

Data Grid - Summaries - Overview

Total Summaries

When the view footer is visible, end-users can right-click it and use a context menu to add and remove summary items. It is also possible to right-click existing summaries to change their aggregate functions.

Data Grid - Total Summary Context Menu

At design time, modify the column GridColumn.SummaryItem property to add a single summary item for this column.

image

If you need more than one summary, click the ellipsis button against the GridColumn.Summary property in Visual Studio’s Property Grid and use the Collection Editor dialog to create summary items.

Data Grid - Summaries - Summary

Refer to the Working with Summaries in Code. Custom Summaries article to learn how to add total summaries in code.

Demos: Data Summaries and Aggregates | Create total and group summaries | Manual total summary

Group Summaries

End-users can manually add and modify group summaries in two cases:

  • when the GridOptionsMenu.ShowGroupSummaryEditorItem is enabled. In this case, users can right-click a grouped column header to invoke a Group Summary Editor dialog.

    Data Grid - Summaries - Group Summary Editor

  • when the group footer is visible (either it already has a group summary item, or the GridOptionsView.GroupFooterShowMode property is set to VisibleAlways). End-users can right-click this footer below the required column and select a summary item type.

    Data Grid - Summaries - Group Footer Menu

At design-time, invoke the Data Grid designer and switch to the “Main | Group Summary Items” tab. Use this designer page to add summary items and set up their properties. GridGroupSummaryItem objects provide the same settings as total summaries, plus one additional setting: the GridGroupSummaryItem.ShowInGroupColumnFooter property allows you to choose whether an item should be displayed in a group row or group footer.

Data Grid - Summaries - Designer

If the GridOptionsBehavior.AlignGroupSummaryInGroupRow property is enabled, all summary items shown in group footers move to group rows below corresponding column headers.

Data Grid - Summaries - Align In Group Row

When you enable multiple row selection mode, the Data Grid can show summaries calculated against groups of rows in the footer.

image

Refer to the GridSummaryItem.Mode topic for more information.

See the Working with Summaries in Code. Custom Summaries article to learn how to add group summaries in code.

Tip

When Data Grid data is grouped by multiple columns, handle the GridView.CustomSummaryExists event to avoid repeating summaries in group footers.

Demos: Data Summaries and Aggregates | Create total and group summaries | Align group summaries in group rows

Sort Groups by Summary Values

When the Data Grid displays group summaries, end-users can right-click a column header in a group panel and select “Sort by Summary”. By doing so, users can sort groups by any group summary item, associated with any Data Grid column. When sorting by summaries is active, a dash is painted above the regular ascending/descending sort indicator in column headers.

Data Grid - Summaries - Sorting by Summaries

To disable the “Sort by Summary” menu item, set the GridOptionsMenu.ShowGroupSortSummaryItems property to false.

In code, add GroupSummarySortInfo objects into the GridView.GroupSummarySortInfo collection.

private void Form1_Load(object sender, EventArgs e) {
    // ... 
    GridColumn firstGroupColumn = gridView.SortInfo[0].Column;
    GroupSummarySortInfo[] groupSummaryToSort = { new GroupSummarySortInfo(summaryItemMaxOrderSum, firstGroupColumn, ColumnSortOrder.Ascending) };
    gridView.GroupSummarySortInfo.ClearAndAddRange(groupSummaryToSort);
}

Note

The Data Grid does not automatically re-sort groups sorted by group summary values when these values change (when new rows are added to the Grid, or existing rows are modified or deleted). To update the group sorting order manually, call the ColumnView.RefreshData method.

Demo: Sorting by Summary Values

Ignore Null Values

Enable the OptionsBehavior.SummariesIgnoreNullValues property to ignore cells with null values during summary calculations.

See Also