GridControl.CustomSummary Event

Allows you to calculate a custom summary.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v20.1.dll


public event CustomSummaryEventHandler CustomSummary
Public Event CustomSummary As CustomSummaryEventHandler

Event Data

The CustomSummary event's data class is CustomSummaryEventArgs. The following properties provide information specific to this event:

Property Description
FieldValue Gets the processed field value.
GroupLevel Gets the nested level of the group whose summary value is being calculated.
GroupRowHandle Gets a value identifying the group row whose child data rows are involved in summary calculation.
IsGroupSummary Gets whether a group summary value is being calculated.
IsTotalSummary Gets whether a total summary value is being calculated.
Item Gets a summary item whose value is being calculated.
Row Gets the currently processed row.
RowHandle Gets the handle of the processed row.
SummaryProcess Gets a value indicating calculation stage.
TotalValue Gets or sets the total summary value.
TotalValueReady Gets or sets whether the Calculation stage of the custom summary calculation process should be skipped.


Total summaries and group summaries have predefined aggregate functions (COUNT, MAX, MIN, SUM, and AVG). To calculate custom summaries, handle the CustomSummary event. This event allows you to implement custom aggregate functions or use a custom algorithm to calculate summary values.

If the GridControl.View property is set to TreeListView, use the TreeListView.CustomSummary event.


The CustomSummary event does not work in Server Mode.

Refer to the Custom Summary topic for more information.


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


A complete sample project is available at

<Window x:Class="CustomSummary_EmptyCells.Window1"
    Title="Window1" Height="350" Width="450" >
        <dxg:GridControl x:Name="grid" CustomSummary="grid_CustomSummary" GroupCount="1">
                <dxg:GridSortInfo FieldName="Text" />
                <dxg:GridColumn FieldName="Text" />
                <dxg:GridColumn FieldName="Number" />
                <dxg:TableView x:Name="view" AutoWidth="True" 
                               NavigationStyle="Cell" ShowTotalSummary="True"/>
                <dxg:GridSummaryItem FieldName="Number" SummaryType="Custom" 
                                     DisplayFormat="Total empty cells count: {0}"/>
                <dxg:GridSummaryItem FieldName="Number" SummaryType="Custom" 
                                     DisplayFormat="Group empty cells count: {0}"/>
using System.Windows;
using System.Collections.Generic;
using DevExpress.Data;
using DevExpress.Xpf.Data;
using DevExpress.Xpf.Grid;
// ...

namespace CustomSummary_EmptyCells {
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window {
        List<TestData> list;
        Dictionary<int, bool> selectedValues = new Dictionary<int, bool>();

        public Window1() {
            list = new List<TestData>();
            for (int i = 0; i < 100; i++) {
                list.Add(new TestData() { Text = "group " + i % 10, Number = i });
                if (i % 3 == 0)
                    list[i].Number = null;
            grid.ItemsSource = list;

        int emptyCellsTotalCount = 0;
        int emptyCellsGroupCount = 0;

        void grid_CustomSummary(object sender, CustomSummaryEventArgs e) {
            if (((GridSummaryItem)e.Item).FieldName != "Number")
            if (e.IsTotalSummary) {
                if (e.SummaryProcess == CustomSummaryProcess.Start) {
                    emptyCellsTotalCount = 0;
                if (e.SummaryProcess == CustomSummaryProcess.Calculate) {
                    int? val = (int?)e.FieldValue;
                    if (!val.HasValue)
                    e.TotalValue = emptyCellsTotalCount;
            if (e.IsGroupSummary) {
                if (e.SummaryProcess == CustomSummaryProcess.Start) {
                    emptyCellsGroupCount = 0;
                if (e.SummaryProcess == CustomSummaryProcess.Calculate) {
                    int? val = (int?)e.FieldValue;
                    if (!val.HasValue)
                    e.TotalValue = emptyCellsGroupCount;

        public class TestData {
            public string Text { get; set; }
            public int? Number { get; set; }
See Also