[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Collapse]Windows 10 App Controls
  Prerequisites
 [Expand]Getting Started
 [Collapse]Controls
  [Expand]Navigation and Layout
  [Expand]Data Editors
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Binding to Data
   [Collapse]Data Management
    [Collapse]Data Summaries
      Total Summary
      Custom Summary
      Group Summary
    [Expand]Grouping
    [Expand]Filtering and Searching
    [Expand]Sorting
   [Expand]Data Editing
   [Expand]Validation
   [Expand]Asynchronous Virtual Source
   [Expand]Data Scrolling
   [Expand]Visual Elements
   [Expand]Examples
  [Expand]Charts
  [Expand]Map Control
  [Expand]Gauges
  [Expand]PDF Viewer
  [Expand]Scheduler
   SVG Icon
   Context Menu
 [Expand]Themes and Color Schemes
  Localization
  Get More Help
 [Expand]API Reference
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Custom Summary

Total summaries provide five predefined aggregate functions. These functions allow you to calculate the following:

  • the number of data rows (Count)
  • the maximum and minimum values (MAX and MIN)
  • the sum and the average value (SUM and AVG).

If you want to calculate summaries using custom rules, handle the GridControl.CustomSummary event. This event enables you to implement custom aggregate functions, or calculate summary values, using a custom algorithm. Custom summaries allow you to:

  • calculate summaries against records that meet specific criteria
  • involve multiple data fields in calculations
  • implement complex summary functions (e.g. the standard deviation of a population), etc.

Expanded General Information

To calculate a summary manually:

The GridControl.CustomSummary event fires for each data row involved in summary calculation. The event is also raised before and after processing rows to enable you to perform any initialization and finalization.

The summary calculation consists of the following three stages:

  • Initialization

    The CustomSummary event is raised once and the DevExpress.Data.CustomSummaryEventArgs.SummaryProcess property is set to CustomSummaryProcess.Start. At this stage you can initialize summary values (e.g. reset internal counters).

  • Calculation

    The CustomSummary event occurs multiple times, once for each data row. The SummaryProcess property is set to CustomSummaryProcess.Calculate. At this stage you should accumulate summaries.

  • Finalization

    The CustomSummary event is raised once and the SummaryProcess property is set to CustomSummaryProcess.Finalize. At this point, calculate a final summary value and assign it to the event parameter's DevExpress.Data.CustomSummaryEventArgs.TotalValue property.

To skip the Calculation stage and calculate a custom summary at the Initialization or Finalization stage, set the event parameter's DevExpress.Data.CustomSummaryEventArgs.TotalValueReady property to true at the Initialization stage. This automatically skips the Calculation stage and the Finalization stage starts immediately.

Expanded Example

The following example demonstrates how to use custom summaries to count the total number of empty cells in a certain grid column.

Note

A complete sample project is available at: https://github.com/DevExpress-Examples/how-to-create-custom-summary-e4333

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