GridSummaryColumnDescriptor scd1 = new GridSummaryColumnDescriptor("SummaryColumn1", Syncfusion.Grouping.SummaryType.Int32Aggregate, "ColumnA", "{Sum}");
GridSummaryColumnDescriptor scd2 = new GridSummaryColumnDescriptor("SummaryColumn2", Syncfusion.Grouping.SummaryType.Int32Aggregate, "ColumnB", "{Sum}");
GridSummaryColumnDescriptor scd3 = new GridSummaryColumnDescriptor("SummaryColumn3", Syncfusion.Grouping.SummaryType.Custom, "ColumnC", "");
GridSummaryRowDescriptor srd = new GridSummaryRowDescriptor();
srd.SummaryColumns.AddRange(new GridSummaryColumnDescriptor[] { scd1, scd2, scd3 });
this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(srd);
this.gridGroupingControl1.QueryCellStyleInfo += GridGroupingControl1_QueryCellStyleInfo;
private void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity == null)
return;
if (e.TableCellIdentity.TableCellType == GridTableCellType.SummaryFieldCell && e.TableCellIdentity.SummaryColumn.Name == "SummaryColumn3")
{
GridSummaryRow row = e.TableCellIdentity.DisplayElement as GridSummaryRow;
if (row != null)
{
int col1 = 0;
int col2 = 0;
foreach (var scd in row.SummaryRowDescriptor.SummaryColumns)
{
if (scd.Name == "SummaryColumn1")
{
var text1 = scd.GetDisplayText(row.ParentGroup);
int.TryParse(text1, out col1);
}
else if (scd.Name == "SummaryColumn2")
{
var text2 = scd.GetDisplayText(row.ParentGroup);
int.TryParse(text2, out col2);
}
}
if (col2 > 0)
e.Style.CellValue = (double)col1 / (double)col2;
}
}
} |