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

GridControl.CustomSummary Event

Allows you to calculate summary values manually.

Namespace: DevExpress.WinUI.Grid

Assembly: DevExpress.WinUI.Grid.v22.1.dll

NuGet Package: DevExpress.WinUI

Declaration

public event CustomSummaryEventHandler CustomSummary

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.
Mode Specifies how summaries are calculated - against all rows or for the selected rows.
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.

The event data class exposes the following methods:

Method Description
GetGroupSummary(Int32, Object) Returns the value of the specified group summary for the specified group row.
GetValue(String) Returns the value in the specified field

Remarks

Total and group summaries have predefined aggregate functions: Sum, Min, Max, Average, and Count. 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.

Example

The following code sample shows how to use a custom summary to count the total value of selected rows:

DevExpress WinUI Grid Control - Custom Summary

<dxg:GridControl x:Name="grid" 
                 ItemsSource="{x:Bind ViewModel.Source}" 
                 AutoGenerateColumns="True" 
                 SelectionMode="Row" 
                 ShowTotalSummary="True" 
                 CustomSummary="grid_CustomSummary" 
                 SelectionChanged="grid_SelectionChanged">
    <dxg:GridControl.TotalSummary>
        <dxg:GridTotalSummaryItem FieldName="UnitPrice" SummaryType="Custom"
                                  DisplayFormat="Total price (selected rows): {0}"/>
    </dxg:GridControl.TotalSummary>
</dxg:GridControl>
using DevExpress.Data;
using DevExpress.WinUI.Grid;
// ...

public sealed partial class MainWindow : Window {
    public MainViewModel ViewModel { get; } = new MainViewModel();
    public MainWindow() {
        this.InitializeComponent();
    }

    double sum;
    void grid_CustomSummary(object sender, CustomSummaryEventArgs e) {
        if(e.SummaryProcess == CustomSummaryProcess.Start) {
            sum = 0;
        } else if(e.SummaryProcess == CustomSummaryProcess.Calculate) {
            if(grid.IsRowSelected(e.RowHandle))
                sum += (double)e.FieldValue;
        } else {
            e.TotalValue = sum;
        }
    }

    void grid_SelectionChanged(object sender, GridSelectionChangedEventArgs e) {
        grid.UpdateTotalSummary();
    }
}

For more information, refer to the following help topic: Custom Summary.

See Also