MultiRow Windows Forms > Developer's Guide > Using MultiRow > Cell Types > SummaryCell > Show Column Sum in Footer (SummaryCell) |
You can use the summary cell to display a column sum in the footer. The example below shows the sum of values entered in the numeric up down cell in the summary cell of the footer.
When calculating a single cell, you can use the CellName property of the MathStatistics class to specify the cell for which you wish to perform the calculation.
Use the following steps to display the sum of a single cell in the footer, using the designer.
Enter a value in the numericUpDownCell1 of each row and the sum is displayed in the footer.
This example creates a summary cell and calculates the values.
Imports GrapeCity.Win.MultiRow Dim numericUpDownCell1 As New NumericUpDownCell() numericUpDownCell1.Name = "numericUpDownCell1" Dim summaryCell1 As New SummaryCell() ' Set display format of cell value. summaryCell1.Style.Format = "###,###" ' Display Sum of cell column "numericUpDownCell1" summaryCell1.Calculation = New MathStatistics(StatisticsType.Sum, "numericUpDownCell1") Dim cells As Cell() = {numericUpDownCell1} Dim template1 As Template = Template.CreateGridTemplate(cells) Dim columnFooterSection1 As ColumnFooterSection = New ColumnFooterSection() summaryCell1.Location = template1.Row.Cells("numericUpDownCell1").Location columnFooterSection1.Cells.Add(summaryCell1) template1.ColumnFooters.Add(columnFooterSection1) GcMultiRow1.Template = template1 |
using GrapeCity.Win.MultiRow; NumericUpDownCell numericUpDownCell1 = new NumericUpDownCell(); numericUpDownCell1.Name = "numericUpDownCell1"; SummaryCell summaryCell1 = new SummaryCell(); // Set display format of cell value. summaryCell1.Style.Format = "###,###"; // Display Sum of cell column "numericUpDownCell1" summaryCell1.Calculation = new MathStatistics(StatisticsType.Sum, "numericUpDownCell1"); Cell[] cells = { numericUpDownCell1 }; Template template1 = Template.CreateGridTemplate(cells); ColumnFooterSection columnFooterSection = new ColumnFooterSection(); summaryCell1.Location = template1.Row.Cells["numericUpDownCell1"].Location; columnFooterSection.Cells.Add(summaryCell1); template1.ColumnFooters.Add(columnFooterSection); gcMultiRow1.Template = template1; |
When calculating multiple cells, you can use the ExpressionString property of the MathStatistics class to set the cells you wish to calculate. Specify the formula string to be used for calculation, in the ExpressionString property.
Use the following steps to display the average of the sum total of multiple cells in the footer.
If you enter values in the numericUpDownCell1 and numericUpDownCell2 of each row, the average of the sum total of each row is displayed in the footer.
The following code calculates multiple cells.
Imports GrapeCity.Win.MultiRow Dim numericUpDownCell1 As New NumericUpDownCell() numericUpDownCell1.Name = "numericUpDownCell1" Dim numericUpDownCell2 As New NumericUpDownCell() numericUpDownCell2.Name = "numericUpDownCell2" Dim summaryCell1 As New SummaryCell() ' Set display format of the cell value summaryCell1.Style.Format = "###,###" ' Display average of the sum total of "numericUpDownCell1" and "numericUpDownCell2" Dim mathStatistics1 As New MathStatistics() mathStatistics1.ExpressionString = "numericUpDownCell1 + numericUpDownCell2" mathStatistics1.StatisticsType = StatisticsType.Average summaryCell1.Calculation = mathStatistics1 Dim cells As Cell() = {numericUpDownCell1, numericUpDownCell2} Dim template1 As Template = Template.CreateGridTemplate(cells) Dim columnFooterSection1 As ColumnFooterSection = New ColumnFooterSection() summaryCell1.Location = template1.Row.Cells("numericUpDownCell1").Location columnFooterSection1.Cells.Add(summaryCell1) template1.ColumnFooters.Add(columnFooterSection1) GcMultiRow1.Template = template1 |
using GrapeCity.Win.MultiRow; NumericUpDownCell numericUpDownCell1 = new NumericUpDownCell(); numericUpDownCell1.Name = "numericUpDownCell1"; NumericUpDownCell numericUpDownCell2 = new NumericUpDownCell(); numericUpDownCell2.Name = "numericUpDownCell2"; SummaryCell summaryCell1 = new SummaryCell(); // Set display format of the cell value summaryCell1.Style.Format = "###,###"; // Display average of the sum total of "numericUpDownCell1" and"numericUpDownCell2" MathStatistics mathStatistics1 = new MathStatistics(); mathStatistics1.ExpressionString = "numericUpDownCell1 + numericUpDownCell2"; mathStatistics1.StatisticsType = StatisticsType.Average; summaryCell1.Calculation = mathStatistics1; Cell[] cells = { numericUpDownCell1, numericUpDownCell2 }; Template template1 = Template.CreateGridTemplate(cells); ColumnFooterSection columnFooterSection = new ColumnFooterSection(); summaryCell1.Location = template1.Row.Cells["numericUpDownCell1"].Location; columnFooterSection.Cells.Add(summaryCell1); template1.ColumnFooters.Add(columnFooterSection); gcMultiRow1.Template = template1; |