Flexible TreeView Flexible TreeView


Support & Community

Summary. Aggregation operations

Previous Table of Contents Next

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 data 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.

but you can easily create own operation as shown below.


Data binding

Before displaying, every summary should be bound through node control to data for which to show the aggregating operation result. Summaries can be bound to a 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`s may be any node control in the treeview.
Note that the specified node control should support the operation, specified in the Operation summary property!

Because summary can be shown for any node either with or without children nodes, we need to decide whether to include all those children nodes into aggregation or only first-level children nodes. To do that, use the IncludeChildrenNodes summary property. When it is enabled (by default), summary aggregates the data of all node`s children nodes and these children nodes` children. Otherwise, summary aggregates only the data of the node`s children 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 data provider`s properties to control the data provider appearance and behavior:

  • Operation – the aggregation operation, implemented by a 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 you 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:

  • Countable – calculates a summary value by iterating through the nodes list. It is Sum/Average/Min/Max data providers;
  • Static - calculates a summary value without iteration. It is the Count data provider.

To implement countable data provider, you need to inherit your class from the ARMSoft.FlexibleTreeView.Summary.Providers.CountableSummaryDataProvider class as shown below:

Example:

// 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 pValue)
  {
    // process each bound data`s item.
    if (pValue != null)
    {
      Value += Convert.ToDecimal(pValue);
    }
  }
 
  protected override void FinishCount(int pValuesCount)
  {
    // finalize counting.
    Value /= 2;
  }
 
  public override bool IsNodeControlSupported(NodeControl pControl)
  {
    // allow to create in run-time our data provider only when the summary is bound to the NodeNumeric node control.
    return pControl 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;

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

Previous Top Next


Last news
Bookmark and Share
Use Flexible TreeView in WPF project
Sunday, 18 December 2011

Do you have a WPF project and want to use Flexible TreeView there? No problem!

Flexible TreeView v3.4
Friday, 16 December 2011

Flexible TreeView v3.4 maintenance release has been released.

Flexible TreeView v3.3
Friday, 23 September 2011

Flexible TreeView v3.3 maintenance release has been released. Separate assemblies for .NET 2.0, 4.0 and 4.0 Client Profile, HTML markup extension, etc.

Latest release

Version:
Release date:
3.4
Dec 16, 2011


Copyright © 2006-2012 ARMSoft. All rights reserved.