wpf-devexpress-dot-xpf-dot-grid-dot-treelistview-4a091511.md
Enables you to calculate summary values manually.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public event TreeListCustomSummaryEventHandler CustomSummary
Public Event CustomSummary As TreeListCustomSummaryEventHandler
The CustomSummary event's data class is TreeListCustomSummaryEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| FieldValue | Gets the processed field value. |
| IsNodeSummary | Gets whether the processed row values are used to calculate a node summary. |
| IsTotalSummary | Gets whether the processed row values are used to calculate a total summary. |
| IsTotalValueReady | Gets or sets whether the Calculation stage of the custom summary calculation process should be skipped. |
| Node | Gets the processed node. |
| SummaryItem | Gets a summary item whose value is being calculated. |
| SummaryProcess | Gets a value indicating the calculation stage. |
| TotalValue | Gets or sets the total summary value. |
Total summaries contain predefined aggregate functions. These functions allow you to calculate the following:
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.
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
<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>
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;
}
}
}
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
ShowNodeFooters="True"
CustomSummary="OnCustomSummary">
<dxg:TreeListView.NodeSummary>
#line 16 "..\..\..\MainWindow.xaml"
((DevExpress.Xpf.Grid.TreeListView)(target)).CustomSummary += new DevExpress.Xpf.Grid.TreeList.TreeListCustomSummaryEventHandler(this.OnCustomSummary);
#ExternalSource("..\..\MainWindow.xaml",16)
AddHandler CType(target,DevExpress.Xpf.Grid.TreeListView).CustomSummary, New DevExpress.Xpf.Grid.TreeList.TreeListCustomSummaryEventHandler(AddressOf Me.OnCustomSummary)
See Also