How to calulate sum of all the columns in the GridSummaryColumnDescriptor collection of a GridSummaryRowDescriptor while on that row.

I have two summary rows define as follows...

GridSummaryColumnDescriptor[] QtySummaryColumns = new GridSummaryColumnDescriptor[SummaryColumnNames.Count];
GridSummaryColumnDescriptor[] DollarSummaryColumns = new GridSummaryColumnDescriptor[SummaryColumnNames.Count];

for (int i = 0; i < SummaryColumnNames.Count; i++)
{
string columnName = SummaryColumnNames[i];
QtySummaryColumns[i] = new GridSummaryColumnDescriptor(string.Format("_Qty{0}{1}", columnName, i), SummaryType.DoubleAggregate, columnName, "{Sum:#,###;(#,###);0}");
DollarSummaryColumns[i] = new GridSummaryColumnDescriptor(string.Format("_Qty{0}{1}", i), SummaryType.Custom, columnName, "{Total:#,###.00;(#,###.00);0.00}");
}

//summary row -> quantity
rowDescriptor = new GridSummaryRowDescriptor("QtySummaryRow", QtySummaryColumns);
this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(rowDescriptor);

//summary row -> dollars
rowDescriptor = new GridSummaryRowDescriptor("DollarSummaryRow", DollarSummaryColumns);
this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(rowDescriptor);



What I want to do is to show the sum of all the summarycolumn in a cell on the same summary row. I want to add another summary column to the summarycolumndescriptor collection as the first summary column to each summary row that will perform a sum ACROSS all the columns in the QtySummaryColumns
GridSummaryColumnDescriptor and do the same for the DollarSummaryColumns.

Is this possible?

Should I just have an SummaryEmptyCell and manually populate that cell with the calculated value using the QueryCellStyleInfo event? How would I accomplish this?

1 Reply

AD Administrator Syncfusion Team December 5, 2006 09:33 AM UTC

Hi James,

This can be achieved by handling the QueryCellStyleInfo event and set the value of SummaryEmptyCell text to sum of the all summary value present in a summary row. You can use the GetSummaries method to get all updated summaries in a GridGroup. Here is a code snippet to show this.

private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
if( e.TableCellIdentity.TableCellType == GridTableCellType.SummaryEmptyCell )
{
Element el = e.TableCellIdentity.DisplayElement;
GridTable table = e.TableCellIdentity.Table;
GridSummaryRow row = e.TableCellIdentity.DisplayElement as GridSummaryRow;
GridSummaryRowDescriptor summaryRowDescriptor = row.SummaryRowDescriptor;
int sum = 0;
foreach( ISummary summary in el.ParentGroup.GetSummaries(table))
{
Int32AggregateSummary Int32summary = summary as Int32AggregateSummary;
if( Int32summary != null)
{
sum += Int32summary.Sum ;
}
}
e.Style.Text = sum.ToString() ;
e.Style.BackColor = Color.DeepPink;
}
}

Here is a sample.
GGCSummary3_f19cec74.zip

Best Regards,
Haneef

Loader.
Up arrow icon