Home Forums WinForms controls Xceed Grid for WinForms How can I add a SummaryRow to a grid? C# Reply To: How can I add a SummaryRow to a grid? C#

User (Old forums)
Member
Post count: 23064

You will need to add it dynamically as the user groups/ungroups the grid. You can use the GroupingUpdated event, and do something like the following in the event handler :

private bool justUpdated = false;

private void gridControl1_GroupingUpdated(object sender, EventArgs e)
{
if( !justUpdated )
{
foreach( Group group in gridControl1.GroupTemplates )
{
if( group.GroupBy != “OrderID” && group.GroupBy != “Quantity” && group.GroupBy != “Discount” )
{
bool summaryPresent = false;
foreach( Row row in group.FooterRows )
{
if( row is SummaryRow )
{
summaryPresent = true;
}
}
if( !summaryPresent )
{
SummaryRow sumRow = new SummaryRow();
group.FooterRows.Add( sumRow );
if( group.GroupBy == “ProductID” )
{
sumRow.TextFormat = “Quantity : %SUM: Quantity%”;
}
else if( group.GroupBy == “UnitPrice” )
{
sumRow.TextFormat = “Discount : %AVG: Discount format=\”0.##\”%”;
}
//else if…
justUpdated = true;
gridControl1.UpdateGrouping();
}
}
}
}
else
{
justUpdated = false;
}
}

Imported from legacy forums. Posted by André (had 5082 views)