windowsforms-devexpress-dot-xtratreelist-dot-treelist-04194008.md
Allows you to specify custom summary values when the control is printed.
Namespace : DevExpress.XtraTreeList
Assembly : DevExpress.XtraTreeList.v25.2.dll
NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList
[DXCategory("Printing")]
public event GetCustomSummaryValueEventHandler GetPrintCustomSummaryValue
<DXCategory("Printing")>
Public Event GetPrintCustomSummaryValue As GetCustomSummaryValueEventHandler
The GetPrintCustomSummaryValue event's data class is GetCustomSummaryValueEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Column | Obtains the Tree List column used by the summary calculations. |
| CustomValue | Gets or sets a value to be displayed within a summary. |
| IsSummaryFooter | Gets a value indicating whether the total or group summary value is to be calculated. |
| Nodes | Gets the nodes collection for which to calculate a custom summary. |
The control can display the following summaries:
The control supports five predefined aggregate functions: Sum, Min, Max, Count, and Average. If these functions do not meet your needs, you can enable Custom mode and handle the GetCustomSummaryValue event to specify a custom summary value.
The Nodes event argument accesses the processed node collection. To enumerate nodes, you can use either a recursive method or an iterator. See the following help topic for more information: Tree Traversal. Use the CustomValue argument to specify a custom summary value.
The GetCustomSummaryValue event allows you to specify custom summary values when the control is displayed on-screen. To specify custom summary values when the control is printed, use the GetPrintCustomSummaryValue event.
The code below displays the number of departments that exceed the specified budget in the summary footer. The code handles the following events:
GetPrintCustomSummaryValue — calculates a custom summary when the control is printed (the budget displayed on-screen appears different when printed).
Note that the ShowSummaryFooter option should be enabled. The SummaryFooter property should be set to Custom. The SummaryFooterStrFormat property specifies the text that contains the calculated value.
using DevExpress.XtraTreeList.Columns;
using DevExpress.XtraTreeList.Nodes;
using DevExpress.XtraTreeList.Nodes.Operations;
treeList1.OptionsView.ShowSummaryFooter = true;
colBUDGET.SummaryFooter = DevExpress.XtraTreeList.SummaryItemType.Custom;
colBUDGET.SummaryFooterStrFormat = "Departments exceeded the budget: {0}";
treeList1.GetPrintCustomSummaryValue += (s, e) => {
if (e.IsSummaryFooter && e.Column == colBUDGET) {
TreeListExceedLimitOperation operation =
new TreeListExceedLimitOperation("BUDGET", 500000);
treeList1.NodesIterator.DoOperation(operation);
e.CustomValue = operation.Result;
}
};
treeList1.GetCustomSummaryValue += (s, e) => {
if (e.IsSummaryFooter && e.Column == colBUDGET) {
TreeListExceedLimitOperation operation =
new TreeListExceedLimitOperation("BUDGET", 100000);
treeList1.NodesIterator.DoOperation(operation);
e.CustomValue = operation.Result;
}
};
// An operation that counts the number of nodes
// that have a specific value in a specific column
public class TreeListExceedLimitOperation : TreeListOperation {
private string fieldName;
private int upperLimit;
private int value;
public TreeListExceedLimitOperation(string fieldName, int upperLimit) {
this.fieldName = fieldName;
this.upperLimit = upperLimit;
value = 0;
}
// This method is called for each node in the control.
public override void Execute(TreeListNode node) {
int nodeValue = Convert.ToInt32(node[fieldName]);
if (nodeValue > upperLimit)
value++;
}
public int Result {
get { return value; }
}
}
Imports DevExpress.XtraTreeList.Columns
Imports DevExpress.XtraTreeList.Nodes
Imports DevExpress.XtraTreeList.Nodes.Operations
treeList1.OptionsView.ShowSummaryFooter = True
colBUDGET.SummaryFooter = DevExpress.XtraTreeList.SummaryItemType.Custom
colBUDGET.SummaryFooterStrFormat = "Departments exceeded the budget: {0}"
AddHandler treeList1.GetPrintCustomSummaryValue, Sub(s, e)
If e.IsSummaryFooter AndAlso e.Column Is colBUDGET Then
Dim operation As New TreeListExceedLimitOperation("BUDGET", 500000)
treeList1.NodesIterator.DoOperation(operation)
e.CustomValue = operation.Result
End If
End Sub
AddHandler treeList1.GetCustomSummaryValue, Sub(s, e)
If e.IsSummaryFooter AndAlso e.Column Is colBUDGET Then
Dim operation As New TreeListExceedLimitOperation("BUDGET", 100000)
treeList1.NodesIterator.DoOperation(operation)
e.CustomValue = operation.Result
End If
End Sub
' An operation that counts the number of nodes
' that have a specific value in a specific column
Public Class TreeListExceedLimitOperation
Inherits TreeListOperation
Private fieldName As String
Private upperLimit As Integer
Private value As Integer
Public Sub New(ByVal fieldName As String, ByVal upperLimit As Integer)
Me.fieldName = fieldName
Me.upperLimit = upperLimit
value = 0
End Sub
' This method is called for each node in the control.
Public Overrides Sub Execute(ByVal node As TreeListNode)
Dim nodeValue As Integer = Convert.ToInt32(node(fieldName))
If nodeValue > upperLimit Then
value += 1
End If
End Sub
Public ReadOnly Property Result() As Integer
Get
Return value
End Get
End Property
End Class
See Also