GrapeCity MultiRow Windows Forms Documentation
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.

Using the Designer

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.

  1. Add the numeric up down cell to a row (for example: numericUpDownCell1).
  2. In Visual Studio, select Template - Add - Column Footer from the menu and add the column footer.
  3. Add the summary cell in the column footer section (for example: summaryCell1).
  4. Select summaryCell1 and from Properties window, set the summaryCell1.Style.Format property to ###,###.
  5. In the Properties window, select MathStatistics from the drop-down list for the summaryCell1.Calculation property.
  6. Click the plus sign to the right of the summaryCell1.Calculation property and expand the MathStatistics object.
  7. Set the StatisticsType property of MathStatistics to Sum.
  8. Set the CellName property of MathStatistics to numericUpDownCell1.
  9. Change the designer document window tab to Runtime.

Enter a value in the numericUpDownCell1 of each row and the sum is displayed in the footer.

Using Code

This example creates a summary cell and calculates the values.

[VB]

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

[CS]

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;

Using the Designer

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.

  1. Add two numeric cells in the Row (for example:numericUpDownCell1, numericUpDownCell2).
  2. Select the Template - Add - Column Footer menu in Visual Studio, and add a column footer (ColumnFooterSection).
  3. Add a summary cell in the ColumnFooterSection (for example:summaryCell1).
  4. Select summaryCell1, and set ###,### in the summaryCell1.Style.Format property, in the property window.
  5. Select MathStatistics from the drop-down list of the summaryCell1.Calculation property.
  6. Click the plus mark on the right of the summaryCell1.Calculation property, and expand the properties of the MathStatistics object.
  7. Set the StatisticsType property of MathStatistics to Average.
  8. Select the ExpressionString property of MathStatistics, and click the ... button.
  9. Set the calculation formula in the Expression Builder that is displayed (for example:numericUpDownCell1 + numericUpDownCell2).
  10. Click the OK button and close the Expression Builder.
  11. Switch the document window tab of the designer to Runtime.

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.

Using Code

The following code calculates multiple cells.

[VB]

 
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

 

[CS]

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;
See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options