Back to Devexpress

TreeList.GetPrintCustomSummaryValue Event

windowsforms-devexpress-dot-xtratreelist-dot-treelist-04194008.md

latest9.7 KB
Original Source

TreeList.GetPrintCustomSummaryValue Event

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

Declaration

csharp
[DXCategory("Printing")]
public event GetCustomSummaryValueEventHandler GetPrintCustomSummaryValue
vb
<DXCategory("Printing")>
Public Event GetPrintCustomSummaryValue As GetCustomSummaryValueEventHandler

Event Data

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

PropertyDescription
ColumnObtains the Tree List column used by the summary calculations.
CustomValueGets or sets a value to be displayed within a summary.
IsSummaryFooterGets a value indicating whether the total or group summary value is to be calculated.
NodesGets the nodes collection for which to calculate a custom summary.

Remarks

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.

Example

The code below displays the number of departments that exceed the specified budget in the summary footer. The code handles the following events:

  • GetCustomSummaryValue — calculates a custom summary (the number of departments) when the control is displayed on-screen.
  • 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.

csharp
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; }
    }
}
vb
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

Print Tree List

SummaryFooter

RowFooterSummary

GetCustomSummaryValue

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace