FlexGrid for WinForms
Step 4 of 4: Include Subtotals and Outline Tree
Show AllShow All
Hide AllHide All

When the grid is used in bound mode, any changes to the data source cause the grid to fire the AfterDataRefresh event. This event is the ideal place to put the code that inserts the subtotals and builds the outline tree for the grid.

Add the following AfterDataRefresh event handler to the form:

To write code in Visual Basic

To write code in C#

Run the program and observe the following:

The code starts by getting the index of the Sale Amount column. In this tutorial, the index will always be the same (Column 6). Looking up the index is usually better than hardwiring it, though, because if someone added a couple of fields to the SQL statement the index would change.

The code then calls the C1FlexGrid.Subtotal method to group the data and insert new rows with the subtotals. The new rows are automatically configured as outline nodes (their IsNode property is set to True), so the subtotals are collapsible.


Try dragging columns around. You can easily see the totals by country, product category, or salesperson. You can also expand tree nodes to drill down into the data if you want to see more detail.


Note also that the grid is editable, changing some values in the Sale Amount column will cause the AfterDataRefresh event to fire again, and the totals will be automatically updated.

This concludes this tutorial.

See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Product Support Forum |  Documentation Feedback