Skip to content

Summary. Aggregation operations#

Every summary displays the result of an aggregation operation over bound data. To change that operation, use the Operation summary property.

Flexible TreeView has these built-in operations:

  • None - used by default and shows nothing.
  • Count - shows the bound data records count.
  • Min - shows the minimal value of bound data.
  • Max - shows the maximal value of bound data.
  • Sum - shows the sum of bound data.
  • Average - shows the average value of bound data.

You can also easily create your own operation as shown below.

Data binding#

Before displaying, every summary should be bound through a node control to data for which to show the aggregating operation result. Summaries can be bound to data only through node controls. To do that, adjust the NodeControl summary property to a node control, through which to retrieve data for aggregation. This may be any node control in the treeview.

Note

The specified node control should support the operation specified in the Operation summary property.

Because a summary can be shown for any node either with or without child nodes, we need to decide whether to include all or only first-level child nodes into aggregation. To do that, use the IncludeChildrenNodes summary property. When it is enabled (by default), summary aggregates the data of all node's child nodes and these child nodes' children. Otherwise, summary aggregates only the data of the node's child nodes.

Data providers#

To process and aggregate bound data, Flexible TreeView has summary data providers that are defined in the Summaries.DataProviders treeview property. Every data provider aggregates data by using one operation, defined in the Operation provider property.

Use the following data provider's properties to control the data provider appearance and behavior:

  • Operation - the aggregation operation, implemented by a specific data provider.
  • OperationName - the aggregation operation's full name to display in the summaries customization dialog.
  • OperationShortName - the aggregation operation's short name to display in the summaries context menu.
  • OperationNameDelimiter - a string that's displayed in the summary between operation name and summary value.
  • DisplayFormat - the data provider aggregated value's custom display format. It allows to define the custom display format for all summaries that use this data provider. The display format's format is equal to the DisplayFormat summary property's format.

Custom data provider#

While Flexible TreeView provides data providers for all general operations, you're free to create your own provider that implements your custom aggregation algorithm.

There are two different types of data providers:

  1. Countable - calculates a summary value by iterating through the nodes list. It is Sum, Average, Min and Max data providers.
  2. Static - calculates a summary value without iteration. It is the Count data provider.

Countable data provider#

To implement a countable data provider, you need to inherit your class from the CountableSummaryDataProvider class as shown below:

// Firstly, create our custom data provider type where we'll return half of the bound data's sum.
class HalfSumDataProvider : CountableSummaryDataProvider
{
  public HalfSumDataProvider()
        // provide long and short operation names.
        : base("Half sum", "HalfSum")
  {
  }

  public override eSummaryOperation Operation
  {
    get
    {
      // our provider's operation unique identifier.
      return (eSummaryOperation)100;
    }
  }

  protected override void StartCount()
  {
    // initialize counting.
    Value = 0;
  }

  protected override void ProcessValue(object value)
  {
    // process each bound data's item.
    if (value != null)
    {
      Value += Convert.ToDecimal(value);
    }
  }

  protected override void FinishCount(int valuesCount)
  {
    // finalize counting.
    Value /= 2;
  }

  public override bool IsNodeControlSupported(NodeControl control)
  {
    // allow to create our custom data provider in run-time only when the summary
    // is bound to a NodeNumeric node control.
    return control is NodeNumeric;
  }
}

// register our provider in the treeview's summary providers list.
HalfSumDataProvider provider = new HalfSumDataProvider();
tree.Summaries.DataProviders.AddProvider(provider);

// use our provider in the summary.
TreeviewSummaryItem summary = new TreeviewSummaryItem();
// numericNodeControl is the NodeNumeric node control instance in our treeview.
summary.NodeControl = numericNodeControl;
summary.Operation = provider.Operation;
Tree.Summaries.Treeview.Add(summary);
Tree.Summaries.Treeview.Visible = true;
Tree.Summaries.Treeview.LevelsCount = 1;
' Firstly, create our custom data provider type where we'll return half of the bound data's sum.
Class HalfSumDataProvider
    Inherits CountableSummaryDataProvider
    Public Sub New()
        ' provide long and short operation names.
        MyBase.New("Half sum", "HalfSum")
    End Sub
    Public Overrides ReadOnly Property Operation() As eSummaryOperation
        Get
            ' our provider's operation unique identifier.
            Return DirectCast(100, eSummaryOperation)
        End Get
    End Property
    Protected Overrides Sub StartCount()
        ' initialize counting.
        Value = 0
    End Sub
    Protected Overrides Sub ProcessValue(value As Object)
        ' process each bound data's item.
        If value IsNot Nothing Then
            Value += Convert.ToDecimal(value)
        End If
    End Sub
    Protected Overrides Sub FinishCount(valuesCount As Integer)
        ' finalize counting.
        Value /= 2
    End Sub
    Public Overrides Function IsNodeControlSupported(control As NodeControl) As Boolean
        ' allow to create our custom data provider in run-time only when the summary
        ' is bound to a NodeNumeric node control.
        Return TypeOf control Is NodeNumeric
    End Function
End Class

' register our provider in the treeview's summary providers list.
Dim provider As New HalfSumDataProvider()
tree.Summaries.DataProviders.AddProvider(provider)
' use our provider in the summary.
Dim summary As New TreeviewSummaryItem()
' numericNodeControl is the NodeNumeric node control instance in our treeview.
summary.NodeControl = numericNodeControl
summary.Operation = provider.Operation
Tree.Summaries.Treeview.Add(summary)
Tree.Summaries.Treeview.Visible = True
Tree.Summaries.Treeview.LevelsCount = 1

Static data provider#

To implement a static data provider, inherit your class from the SummaryDataProviderBase class and override GetSummaryValue and IsNodeControlSupported methods. You can use your static data provider as a countable provider as shown above.