Back to Devexpress

Tutorial: Total Summaries

windowsforms-114624-controls-and-libraries-data-grid-getting-started-walkthroughs-summaries-tutorial-total-summaries.md

latest5.8 KB
Original Source

Tutorial: Total Summaries

  • Apr 04, 2023
  • 4 minutes to read

This walkthrough is a transcript of the Total Summaries video available on the DevExpress YouTube Channel.

DevExpress GridControl allows you to display total values, such as the number of records and the maximum and minimum values in a column. In this tutorial, you will learn how end users can add or remove totals using built-in footer menus, how to prevent them from customizing the totals you have specified, and how to predefine the grid totals at design time or in code.

Starting Point

Start with a GridControl displaying simple task data.

To enable total summary display and end-user interaction, you need to show the View Footer. To do this, expand the View’s GridView.OptionsView property and turn on the GridOptionsView.ShowFooter option.

End-User Capabilities

Since the View’s footer is now visible, end users can add total summaries using footer context menus. Right-click the footer under the Unit Price column and select Count.

The footer cell now shows the total record count. In the Count column, show the sum of column values.

If you right-click an existing total summary cell, the Add New Summary menu item becomes available.

Use this item to create an additional summary that calculates the maximum value in the Unit Price column. You can also change a function used in a footer cell. Right-click the Count total summary and change the summary function to Min.

To hide a specific total value, right-click it and select None in the context menu. To hide all summaries under a specific column, use the Clear Summary Items option.

Restricting End-User Capabilities

If you don’t want end users to change predefined summaries, go to the Property grid that displays the View’s settings, expand the GridView.OptionsMenu property, and disable the GridOptionsMenu.EnableFooterMenu option. This disables the context menus and thus an end user’s ability to manipulate summaries.

Creating Total Summaries at Design Time

The next step is to see how you can create total summaries at design time.

  • Creating a Single Summary

  • Creating Multiple Summaries

Creating Total Summaries in Code

Finally, create total summaries in code. Write the Click event handler for the Create Summaries button. The handler creates two new GridColumnSummaryItem objects with the required summary types, field names, and display formats. It then adds them to the GridColumn.Summary collection of the Count column.

csharp
private void btn_CreateSummaries_ItemClick(object sender, ItemClickEventArgs e) {
    GridColumnSummaryItem item1 = new GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Max, "Count", "MAX Count={0}");
    GridColumnSummaryItem item2 = new GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Min, "Count", "MIN Count={0}");
    gridView.Columns["Count"].Summary.Add(item1);
    gridView.Columns["Count"].Summary.Add(item2);
}

Run the application and click the Create Summaries button. As a result, the Count column’s footer displays the two specified totals.

See Also

Tutorial: Group Summaries

Tutorial: Format Summary Text

Tutorial: Obtain Summary Values

Tutorial: Sort Group Rows by Summary Values

Tutorial: Custom Summary Functions

Summaries

View Footer