Summary. Get Started#
Summary allows you to display the result of aggregation operations over bound data in the treeview.
To define summaries, use the Summaries treeview property. You can customize summaries either in run-time or design-time using the summaries designer.
Every summary item has these core properties to define summary behavior:
- Operation - defines which operation's result to display in the summary.
- NodeControl - defines from which node control to get data to aggregate.
- Column - defines in which column to show the summary (optional, for the treeview with columns only).
- DataProvider - allows overriding the summary aggregation logic.
To display the summary:
- Define which operation's result this summary will show by filling the Operation summary property.
- Define where to get data to aggregate by filling the NodeControl summary property.
- If you have a treeview with columns, define in which column to show your summary using the Column summary property.
Warning
To display summaries, the summary levels count greater than 1 should be explicitly set as described below!
Operation#
The Operation summary property specifies which aggregation operation should be used. The specified aggregation operation runs over the list of treeview nodes. This nodes list depends on the selected summary type, which is described below. To define which node value to use when aggregating the data the NodeControl summary property is used, as described below.
Flexible TreeView supports the following operations out-of-box:
- Count - shows the count of nodes that the summary is processing.
- Max - shows the maximal bound value.
- Min - shows the minimal bound value.
- Average - shows the average of bound values.
- Sum - shows the sum of bound values.
- Custom - allows specifying a custom aggregation logic as described here.
NodeControl#
The NodeControl summary property defines which node's value to use when aggregating the data. The specified node control is bound to a node's property which data to use when calculating the summary value.
Column#
In the treeview with columns, you need to decide in which column to show every summary. To do that, use the Column summary property. In the treeview without columns, it doesn't matter whether you define a column or not; all summaries will be shown.
Data Provider#
The summaries allow specifying the aggregation operation (using the Operation property) that will be used to calculate its value. In case you need an aggregation logic that is not built into Flexible TreeView, a custom data provider could be created and assigned to the DataProvider summary property. Read this topic for details.
Summary Types#
Summaries can be one of these types:
- Node summaries (
1
on the picture below) - allows to define node's personal summaries, shown only for the specified node. All Node summaries are stored in the Summaries.Node treeview property. - Nodes summaries (
2
) - shows summaries inside all non-root nodes which don't have personal summaries. It allows to define summaries only once to show for all nodes. All Nodes summaries are stored in the Summaries.Nodes treeview property. - Treeview summaries (
3
) - allows to show summaries for root nodes at the bottom of treeview. All Treeview summaries are stored in the Summaries.Treeview treeview property.
Note
Both Node and Nodes summaries will be shown only inside non-root nodes or any child nodes, while Treeview summaries will be shown only for root nodes.
Node summaries#
Node summaries allow you to define node's personal summaries, shown only for the specified node. To define a Node summary, use the Summaries.Node treeview property and NodeSummaryItem type as shown below:
NodeTextBox tb = new NodeTextBox();
tb.AttachTo(tree);
Node root = new Node("Test");
root.AttachTo(tree);
Node child = new Node("child node");
child.AttachTo(root);
NodeSummaryItem sum = new NodeSummaryItem();
// set the node where to display the summary.
sum.Node = root;
sum.NodeControl = tb;
sum.Operation = eSummaryOperation.Count;
tree.Summaries.Node.Add(sum);
Dim tb As New NodeTextBox()
tb.AttachTo(tree)
Dim root As New Node("Test")
root.AttachTo(tree)
Dim child As New Node("child node")
child.AttachTo(root)
Dim sum As New NodeSummaryItem()
' set the node where to display the summary.
sum.Node = root
sum.NodeControl = tb
sum.Operation = eSummaryOperation.Count
tree.Summaries.Node.Add(sum)
Note
To display the Node summary, you need to set the node for which to show this summary!
Nodes summaries#
Nodes summaries show summaries inside all non-root nodes which don't have personal summaries. It allows you to define summaries only once to show for all nodes. To define a Nodes summary, use the Summaries.Nodes treeview property and NodeSummaryItem type as shown below:
Example:
NodeTextBox tb = new NodeTextBox();
tb.AttachTo(tree);
Node root = new Node("Test");
root.AttachTo(tree);
Node child = new Node("child node");
child.AttachTo(root);
root = new Node("Test 2");
root.AttachTo(tree);
child = new Node("child node 2");
child.AttachTo(root);
NodesSummaryItem sum = new NodesSummaryItem();
sum.NodeControl = tb;
sum.Operation = eSummaryOperation.Count;
tree.Summaries.Nodes.Add(sum);
Dim tb As New NodeTextBox()
tb.AttachTo(tree)
Dim root As New Node("Test")
root.AttachTo(tree)
Dim child As New Node("child node")
child.AttachTo(root)
root = New Node("Test 2")
root.AttachTo(tree)
child = New Node("child node 2")
child.AttachTo(root)
Dim sum As New NodesSummaryItem()
sum.NodeControl = tb
sum.Operation = eSummaryOperation.Count
tree.Summaries.Nodes.Add(sum)
Treeview summaries#
Treeview summaries allow you to show summaries for root nodes at the bottom of treeview. To define a Treeview summary, use the Summaries.Treeview treeview property and TreeviewSummaryItem type as shown below:
NodeTextBox tb = new NodeTextBox();
tb.AttachTo(tree);
Node root = new Node("Test");
root.AttachTo(tree);
Node child = new Node("child node");
child.AttachTo(root);
TreeviewSummaryItem sum = new TreeviewSummaryItem();
sum.NodeControl = tb;
sum.Operation = eSummaryOperation.Count;
tree.Summaries.Treeview.Add(sum);
You can control the visibility for each of these summary types using the Visible property (disabled by default).
For example, to show Treeview summaries enable the Treeview.Visible property, as shown below:
Summary levels#
Every summary type is a collection of summaries, where each summary can be positioned on any level.
Summary levels allow you to flexibly display many summaries in the treeview. To control summary levels use:
- LevelsCount summary type's property for Nodes and Treeview summary types.
- SummaryLevelsCount node property for Node summary type.
Note
The SummaryLevelsCount node property has special value -1
that hides all summaries for the specified node even if Nodes summaries are defined.
For example, use the code sample below to display multiple summary levels for a node:
// Define custom node class
class EmployeeNode : Node
{
public decimal Salary;
}
// Create node controls
NodeTextBox tb = new NodeTextBox();
tb.AttachToColumn(employeeNameColumn);
tb.AttachTo(tree);
NodeNumeric num = new NodeNumeric();
num.DataFieldName = "Salary";
num.AttachToColumn(employeeSalaryColumn);
num.AttachTo(tree);
// Create the node where to display summaries
EmployeeNode root = new EmployeeNode();
root.AttachTo(tree);
// Create child nodes with data for aggregation
EmployeeNode node = new EmployeeNode();
node.Text = "John";
node.Salary = 5000;
node.AttachTo(root);
node = new EmployeeNode();
node.Text = "Amanda";
node.Salary = 7000;
node.AttachTo(root);
// Add summaries
// Summary for the first level
NodeSummaryItem summary = new NodeSummaryItem();
// Display an average value of bound data
summary.Operation = eSummaryOperation.Average;
// For which node to display the summary
summary.Node = root;
// Where to get data for aggregation
summary.NodeControl = num;
// Optionally: display the summary in the specified treeview column
// summary.Column = employeeSalaryColumn;
tree.Summaries.Node.Add(summary);
// Summary for the second level
summary = new NodeSummaryItem();
summary.Operation = eSummaryOperation.Sum;
summary.Node = root;
summary.NodeControl = num;
// Display summary on the second level
summary.WrapToNextLevel = true;
// Optionally: display the summary in the specified treeview column
//summary.Column = employeeSalaryColumn;
tree.Summaries.Node.Add(summary);
// Setup summaries
// Display summaries
tree.Summaries.Node.Visible = true;
// Display two summary levels for the specified node
root.SummaryLevelsCount = 2;
' Define custom node class
Class EmployeeNode
Inherits Node
Public Salary As Decimal
End Class
' Create node controls
Dim tb As New NodeTextBox()
tb.AttachToColumn(employeeNameColumn)
tb.AttachTo(tree)
Dim num As New NodeNumeric()
num.DataFieldName = "Salary"
num.AttachToColumn(employeeSalaryColumn)
num.AttachTo(tree)
' Create the node where to display summaries
Dim root As New EmployeeNode()
root.AttachTo(tree)
' Create child nodes with data for aggregation
Dim node As New EmployeeNode()
node.Text = "John"
node.Salary = 5000
node.AttachTo(root)
node = New EmployeeNode()
node.Text = "Amanda"
node.Salary = 7000
node.AttachTo(root)
' Add summaries
' Summary for the first level
Dim summary As New NodeSummaryItem()
' Display an average value of bound data
summary.Operation = eSummaryOperation.Average
' For which node to display the summary
summary.Node = root
' Where to get data for aggregation
summary.NodeControl = num
' Optionally: display the summary in the specified treeview column
' summary.Column = employeeSalaryColumn
tree.Summaries.Node.Add(summary)
' Summary for the second level
summary = New NodeSummaryItem()
summary.Operation = eSummaryOperation.Sum
summary.Node = root
summary.NodeControl = num
' Display summary on the second level
summary.WrapToNextLevel = True
' Optionally: display the summary in the specified treeview column
'summary.Column = employeeSalaryColumn
tree.Summaries.Node.Add(summary)
' Setup summaries
' Display summaries
tree.Summaries.Node.Visible = True
' Display two summary levels for the specified node
root.SummaryLevelsCount = 2