Back to Devexpress

TreeListView.CustomSummary Event

wpf-devexpress-dot-xpf-dot-grid-dot-treelistview-4a091511.md

latest7.3 KB
Original Source

TreeListView.CustomSummary Event

Enables you to calculate summary values manually.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public event TreeListCustomSummaryEventHandler CustomSummary
vb
Public Event CustomSummary As TreeListCustomSummaryEventHandler

Event Data

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

PropertyDescription
FieldValueGets the processed field value.
IsNodeSummaryGets whether the processed row values are used to calculate a node summary.
IsTotalSummaryGets whether the processed row values are used to calculate a total summary.
IsTotalValueReadyGets or sets whether the Calculation stage of the custom summary calculation process should be skipped.
NodeGets the processed node.
SummaryItemGets a summary item whose value is being calculated.
SummaryProcessGets a value indicating the calculation stage.
TotalValueGets or sets the total summary value.

Remarks

Total summaries contain 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 Average )

Use the CustomSummary event to apply custom rules to calculate summaries. This event allows you to implement custom aggregate functions or use a custom algorithm to calculate summary values.

If you want to maintain a clean MVVM pattern and specify custom summaries in a View Model, create a command and bind it to the CustomSummaryCommand property.

Refer to the following help topic for more information: Custom Summary.

Example

The following example demonstrates how to calculate custom node summaries in the TreeListView. To do this, handle TreeListView’s CustomSummary event and use the IsNodeSummary property to determine whether to calculate node summaries.

View Example: How to calculate custom Node Summaries in TreeListView

xaml
<dxg:TreeListControl AutoGenerateColumns="AddNew" Name="grid">
    <dxg:TreeListControl.View>
        <dxg:TreeListView AutoExpandAllNodes="True" AutoWidth="True" 
                          KeyFieldName="ID" ParentFieldName="ParentID" 
                          ShowNodeFooters="True" 
                          CustomSummary="OnCustomSummary">
            <dxg:TreeListView.NodeSummary>
                <dxg:TreeListSummaryItem FieldName="Statistics" SummaryType="Custom"/>
            </dxg:TreeListView.NodeSummary>
        </dxg:TreeListView>
    </dxg:TreeListControl.View>
</dxg:TreeListControl>
cs
void OnCustomSummary(object sender, TreeListCustomSummaryEventArgs e) {
    if(e.IsNodeSummary && e.SummaryItem.FieldName == "Statistics") {
        if(e.SummaryProcess == CustomSummaryProcess.Calculate) {
            e.TotalValue = Convert.ToDouble(e.TotalValue) + (double)e.FieldValue;
        }
    }
}
vb
Private Sub OnCustomSummary(ByVal sender As Object, ByVal e As TreeListCustomSummaryEventArgs)
    If e.IsNodeSummary AndAlso Equals(e.SummaryItem.FieldName, "Statistics") Then
        If e.SummaryProcess = CustomSummaryProcess.Calculate Then
            e.TotalValue = Convert.ToDouble(e.TotalValue) + CDbl(e.FieldValue)
        End If
    End If
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomSummary event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-tree-list-calculate-custom-node-summaries/CS/CustomNodeSummaries_CodeBehind/MainWindow.xaml#L16

xml
ShowNodeFooters="True"
              CustomSummary="OnCustomSummary">
<dxg:TreeListView.NodeSummary>

wpf-tree-list-calculate-custom-node-summaries/CS/CustomNodeSummaries_CodeBehind/obj/Debug/net8.0-windows/MainWindow.g.cs#L93

csharp
#line 16 "..\..\..\MainWindow.xaml"
((DevExpress.Xpf.Grid.TreeListView)(target)).CustomSummary += new DevExpress.Xpf.Grid.TreeList.TreeListCustomSummaryEventHandler(this.OnCustomSummary);

wpf-tree-list-calculate-custom-node-summaries/VB/CustomNodeSummaries_CodeBehind/obj.NetFX/Debug/MainWindow.g.vb#L93

vb
#ExternalSource("..\..\MainWindow.xaml",16)
AddHandler CType(target,DevExpress.Xpf.Grid.TreeListView).CustomSummary, New DevExpress.Xpf.Grid.TreeList.TreeListCustomSummaryEventHandler(AddressOf Me.OnCustomSummary)

See Also

TreeListView Class

TreeListView Members

DevExpress.Xpf.Grid Namespace