[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Collapse]Data Grid
   [Collapse]Get Started With Data Grid and Views
     [Expand]Appearance and Conditional Formatting
     [Expand]Data Editing
     [Expand]Hit Information
     [Expand]Data Binding and Working with Columns
     [Expand]Grid View - Columns, Rows and Cells
     [Expand]Banded Views
     [Expand]WinExplorer View
     [Expand]Tile View
     [Expand]Filter and Search
       Tutorial: Custom Summary Functions
       Tutorial: Format Summary Text
       Tutorial: Group Summaries
       Tutorial: Obtain Summary Values
       Tutorial: Sort Group Rows by Summary Values
       Tutorial: Total Summaries
     [Expand]Split Presentation
     [Expand]Row Preview Sections
   [Expand]Data Binding
    Unbound Columns
   [Expand]Data Editing and Validation
   [Expand]Filter and Search
   [Expand]Focus and Selection Handling
    Format Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
    Split Presentation
    Row Preview Sections
   [Expand]Batch Modifications
    Hit Information
    Popup Menus
   [Expand]Save and Restore Layout
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Tutorial: Total Summaries

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, the maximum and minimum values in a column, and so on. 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 pre-define the grid totals at design-time or in code.

Expanded Starting Point

Start with a GridControl displaying simple task data.

Expanded Displaying the View Footer

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.

Expanded 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.

Expanded Restricting End-User Capabilities

If you don't want end-users to change predefined summaries, go to the Property grid displaying 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.

Expanded 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

    Select the Unit Price column and expand its GridColumn.SummaryItem property. Leave the GridSummaryItem.FieldName property unchanged (its purpose will be discussed later). Set the GridSummaryItem.SummaryType property to SummaryItemType.Sum to specify the desired aggregate function. Finally, customize the summary value text formatting by setting the GridSummaryItem.DisplayFormat property.

    Run the application and note the specified summary value is displayed in the grid's footer.

    Then, use the GridSummaryItem.FieldName property that was left unchanged. Go to the Property grid displaying the Unit Price total summary settings and set the GridSummaryItem.FieldName property to the OrderSum field. You'll see that the summary value has changed as now, another field's values are used to calculate the total value.

  • Creating Multiple Summaries

    Return to design time and see how you can create multiple total summaries under a single column. Select the Order Sum column and click the ellipsis button next to the GridColumn.Summary property. This invokes a collection editor with one summary item already in the list, but having its summary type set to SummaryItemType.None. Change the type to SummaryItemType.Max to display the maximum value in the Order Sum column. The GridSummaryItem.DisplayFormat property is automatically changed. Add two new items by clicking the Add button. In the same manner, set their GridSummaryItem.SummaryType property to SummaryItemType.Min and SummaryItemType.Average, respectively. After that, click OK to save the changes and close the editor.

    Run the application again. The Order Sum column's footer displays three separate total values one under another.

Expanded 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. After that, it adds them to the GridColumn.Summary collection of the Count column.

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

Expanded See Also

Is this topic helpful?​​​​​​​