Home Forums WinForms controls Xceed Grid for WinForms Sum of values in group in title Reply To: Sum of values in group in title

User (Old forums)
Member
Post count: 23064

This worked for me. It’s in C#. Hook into the GroupingUpdated event for the grid. This fires whenever the user modifies or creates a group. Inside the event, check each group’s datarows and add up the column. Simple. For a grid with lot’s of data, this might be slow. But as cumbersome as it looks, it’s actually quite zippy. Give it a try.

grid.GroupingUpdated +=new EventHandler(grid_GroupingUpdated);
private void grid_GroupingUpdated(object sender, EventArgs e)
{
foreach(Group grp in grid.Groups)
{
Xceed.Grid.Collections.ReadOnlyDataRowList rows = grp.GetSortedDataRows(false);
int myTotal = 0;
for (int i = 0; i < rows.Count; i++)
{
myTotal += Convert.ToInt32(rows[0].Cells[“<CellToSum>”].Value);
}
grp.Title = “Total Amount = ” + myTotal.ToString();
}
}

Imported from legacy forums. Posted by MBonafe (had 549 views)