C1.Win.C1FlexGrid Namespace > C1FlexGridBase Class > Subtotal Method : Subtotal(AggregateEnum,Int32,Int32,Int32,Int32,String) Method |
'Declaration
Public Overloads Sub Subtotal( _ ByVal aggType As AggregateEnum, _ ByVal level As Integer, _ ByVal groupFrom As Integer, _ ByVal groupTo As Integer, _ ByVal totalOn As Integer, _ ByVal caption As String _ )
'Usage
Dim instance As C1FlexGridBase Dim aggType As AggregateEnum Dim level As Integer Dim groupFrom As Integer Dim groupTo As Integer Dim totalOn As Integer Dim caption As String instance.Subtotal(aggType, level, groupFrom, groupTo, totalOn, caption)
The Subtotal(AggregateEnum,Int32,Int32,Int32,Int32,String) method inserts rows containing aggregate values. These new rows are set to behave as tree nodes so they can be collapsed and expanded to display a dynamic hierarchical outline.
You can control the appearance and behavior of the outline tree using the Tree property.
The node rows added by the Subtotal(AggregateEnum,Int32,Int32,Int32,Int32,String) method have their RowCol.Style property automatically set to one of the Styles.Subtotal* styles. You can use the Styles collection to modify the appearance of all subtotal rows on the grid.
To create an outline tree manually, insert node rows using the RowCollection.InsertNode method, or convert regular rows into nodes by setting the Row.IsNode property to true for the node rows. Then use the Node.Level property to set the outline level for the new nodes.
The code below assumes a grid with four columns: "Product", "Region", "Employee", and "Sales".
The code groups on the first two columns, calculating total sales for each product and for each region within each product.
If the user drags a column to a new position, the tree is automatically rebuilt to show the new grouping (by Employee, Region, etc).
void UpdateTotals() { // no repainting until we're done _flex.Redraw = false; // clear old subtotals, if any _flex.Subtotal(AggregateEnum.Clear); // sort the grid on the columns that will be grouped _flex.Sort(SortFlags.Ascending, 0, 3); // show outline tree on column 0 _flex.Tree.Column = 0; // get a grand total (use -1 instead of column index) _flex.Subtotal(AggregateEnum.Sum, -1, -1, 3, "Grand Total"); // total on column 0 (initially Product) _flex.Subtotal(AggregateEnum.Sum, 0, 0, 3); // total on column 1 (initially Region) _flex.Subtotal(AggregateEnum.Sum, 1, 1, 3); // show outline level 1 _flex.Tree.Show(1); // restore painting _flex.Redraw = true; } void _flex_AfterDragColumn(object sender, C1.Win.C1FlexGrid.DragRowColEventArgs e) { UpdateTotals(); // user moved a column, update totals }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2