[]
        
(Showing Draft Content)

C1.Win.FlexGrid.C1FlexGridBase.Subtotal

Subtotal Method

Subtotal(AggregateEnum, int, int, int, int, string, AggregateFlags)

Groups rows based on cell contents and calculates aggregate values.

Declaration
public void Subtotal(AggregateEnum aggType, int level, int groupFrom, int groupTo, int totalOn, string caption, AggregateFlags options)
Parameters
Type Name Description
AggregateEnum aggType

AggregateEnum value that specifies the type of aggregate to calculate.

int level

Outline level to assign to the new subtotal rows. This parameter allows the creation of multi-level subtotals and affects the display of the outline tree.

int groupFrom

First column in the range used to detect group breaks.

int groupTo

Last column in the range used to detect group breaks.

int totalOn

Column that contains values to be aggregated (usually numeric).

string caption

Text to insert in the subtotal rows.

AggregateFlags options

Options to use when calculating the aggregates.

Remarks

The C1.Win.FlexGrid.C1FlexGridBase.Subtotal(C1.Win.FlexGrid.AggregateEnum,System.Int32,System.Int32,System.Int32,System.Int32,System.String,C1.Win.FlexGrid.AggregateFlags,C1.Win.FlexGrid.RowColFlags) 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 C1.Win.FlexGrid.C1FlexGridBase.Subtotal(C1.Win.FlexGrid.AggregateEnum,System.Int32,System.Int32,System.Int32,System.Int32,System.String,C1.Win.FlexGrid.AggregateFlags,C1.Win.FlexGrid.RowColFlags) method have their 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 InsertNode(int, int) method, or convert regular rows into nodes by setting the IsNode property to true for the node rows. Then use the Level property to set the outline level for the new nodes.

Examples

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, DragRowColEventArgs e)        
{
  UpdateTotals(); // user moved a column, update totals
}

Subtotal(AggregateEnum, int, int, int, int, string)

Groups rows based on cell contents and calculates aggregate values.

Declaration
public void Subtotal(AggregateEnum aggType, int level, int groupFrom, int groupTo, int totalOn, string caption)
Parameters
Type Name Description
AggregateEnum aggType

AggregateEnum value that specifies the type of aggregate to calculate.

int level

Outline level to assign to the new subtotal rows. This parameter allows the creation of multi-level subtotals and affects the display of the outline tree.

int groupFrom

First column in the range used to detect group breaks.

int groupTo

Last column in the range used to detect group breaks.

int totalOn

Column that contains values to be aggregated (usually numeric).

string caption

Text to insert in the subtotal rows.

Subtotal(AggregateEnum, int, int, int, string)

Groups rows based on cell contents and calculates aggregate values.

Declaration
public void Subtotal(AggregateEnum aggType, int level, int groupOn, int totalOn, string caption)
Parameters
Type Name Description
AggregateEnum aggType

AggregateEnum value that specifies the type of aggregate to calculate.

int level

Outline level to assign to the new subtotal rows. This parameter allows the creation of multi-level subtotals and affects the display of the outline tree.

int groupOn

Column used to detect group breaks.

int totalOn

Column that contains values to be aggregated (usually numeric).

string caption

Text to insert in the subtotal rows.

Subtotal(AggregateEnum, int, int, int)

Groups rows based on cell contents and calculates aggregate values.

Declaration
public void Subtotal(AggregateEnum aggType, int level, int groupOn, int totalOn)
Parameters
Type Name Description
AggregateEnum aggType

AggregateEnum value that specifies the type of aggregate to calculate.

int level

Outline level to assign to the new subtotal rows. This parameter allows the creation of multi-level subtotals and affects the display of the outline tree.

int groupOn

Column used to detect group breaks.

int totalOn

Column that contains values to be aggregated (usually numeric).

Subtotal(AggregateEnum)

Groups rows based on cell contents and calculates aggregate values.

Declaration
public void Subtotal(AggregateEnum aggType)
Parameters
Type Name Description
AggregateEnum aggType

AggregateEnum value that specifies the type of aggregate to calculate.

Remarks

This version of the C1.Win.FlexGrid.C1FlexGridBase.Subtotal(C1.Win.FlexGrid.AggregateEnum,System.Int32,System.Int32,System.Int32,System.Int32,System.String,C1.Win.FlexGrid.AggregateFlags,C1.Win.FlexGrid.RowColFlags) method does not take any column parameters, and is useful only for clearing the subtotals. For example:

flex.Subtotal(AggregateEnum.Clear); // clear all subtotals

Subtotal(AggregateEnum, int, string, string, string, string)

Groups rows based on cell contents and calculates aggregate values.

Declaration
public void Subtotal(AggregateEnum aggType, int level, string groupFrom, string groupTo, string totalOn, string caption)
Parameters
Type Name Description
AggregateEnum aggType

AggregateEnum value that specifies the type of aggregate to calculate.

int level

Outline level to assign to the new subtotal rows. This parameter allows the creation of multi-level subtotals and affects the display of the outline tree.

string groupFrom

Name of the first column in the range used to detect group breaks.

string groupTo

Name of the last column in the range used to detect group breaks.

string totalOn

Name of the column that contains values to be aggregated (usually numeric).

string caption

Text to insert in the subtotal rows.

Remarks

This is a variant of the Subtotal(AggregateEnum, int, int, int, int, string, AggregateFlags) method that takes column names instead of indices.

Subtotal(AggregateEnum, int, string, string, string)

Groups rows based on cell contents and calculates aggregate values.

Declaration
public void Subtotal(AggregateEnum aggType, int level, string groupOn, string totalOn, string caption)
Parameters
Type Name Description
AggregateEnum aggType

AggregateEnum value that specifies the type of aggregate to calculate.

int level

Outline level to assign to the new subtotal rows. This parameter allows the creation of multi-level subtotals and affects the display of the outline tree.

string groupOn

Name column used to detect group breaks.

string totalOn

Name of the column that contains values to be aggregated (usually numeric).

string caption

Text to insert in the subtotal rows.

Remarks

This is a variant of the Subtotal(AggregateEnum, int, int, int, string) method that takes column names instead of indices.

Subtotal(AggregateEnum, int, string, string)

Groups rows based on cell contents and calculates aggregate values.

Declaration
public void Subtotal(AggregateEnum aggType, int level, string groupOn, string totalOn)
Parameters
Type Name Description
AggregateEnum aggType

AggregateEnum value that specifies the type of aggregate to calculate.

int level

Outline level to assign to the new subtotal rows. This parameter allows the creation of multi-level subtotals and affects the display of the outline tree.

string groupOn

Name column used to detect group breaks.

string totalOn

Name of the column that contains values to be aggregated (usually numeric).

Remarks

This is a variant of the Subtotal(AggregateEnum, int, int, int) method that takes column names instead of indices.