This sample demonstrates the implementation of custom summaries and custom counters.
Features:
In this image, the last two columns show the custom counters
One counter automatically counts the quantity of all the records while the other counter counts the quantity of only the visible records (with a filter set [UnitPrice] <> 20).
Changing the quantity in one record will automatically update all subsequent records.
Examples for custom summaries are shown at the bottom of the grid.
A simple custom summary counts only the total value while an advanced summary can create a vector of values and perform statistical functions.
The following code shows how to set up an integrated summary.
GridSummaryColumnDescriptor sd0 = new GridSummaryColumnDescriptor(); sd0.DataMember = "Quantity"; sd0.DisplayColumn = "Quantity"; sd0.Format = "{Average:#.00}"; sd0.SummaryType = SummaryType.DoubleAggregate; // Adding SummaryRow with the SummaryColumn. this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(new GridSummaryRowDescriptor("Row 0", "Average", sd0));
The following code shows how to set up custom summaries.
GridSummaryColumnDescriptor sd3 = new GridSummaryColumnDescriptor(); sd3.Name = "QuantityMedian"; sd3.DataMember = "Quantity"; sd3.DisplayColumn = "Quantity"; sd3.Format = "{Median}"; // Declaring the Summary type to be Custom. sd3.SummaryType = SummaryType.Custom; // Adding the SummaryColumn to the SummaryRow. this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(new GridSummaryRowDescriptor("Row 3", "Statistic Median", sd3));
Interactive Features:
Subscribe to the Table_QueryCustomCount event and fill in the custom counter. This event is called for by every record in the table. The custom counter will increase whether or not a record meets the filter criteria.
private void Table_QueryCustomCount(object sender, CustomCountEventArgs e) { if (e.Record is AddNewRecord) return; object obj = e.Record.GetValue(quantityFieldDescriptor); double quantity = Convert.ToDouble(obj); e.CustomCount = quantity; }
Subscribe to the Table_QueryVisibleCustomCounter event and fill in the visible custom counter. This event is called for by every visible record in the table. The custom counter will increase only for records that meet the filter criteria.
private void Table_QueryVisibleCustomCount(object sender, CustomCountEventArgs e) { if (e.Record is AddNewRecord) return; object obj = e.Record.GetValue(quantityFieldDescriptor); double quantity = Convert.ToDouble(obj); e.CustomCount = quantity; }