Skip to main content

TreeList.GetPrintCustomSummaryValue Event

Allows you to specify custom summary values when the control is printed.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v24.2.dll

Declaration

[DXCategory("Printing")]
public event GetCustomSummaryValueEventHandler GetPrintCustomSummaryValue

Event Data

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.

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.

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; }
    }
}
See Also