How to create summaries for GridGroupingControl that update dynamically based on the current selection?

What I'm trying to do is, to display some data in a grid and add a "selection-based-total".

Simply put, it shows the sum of a a particular column in the grid, but only of those rows that are currently selected.

My current approach:
I've created a custom summary class. And to refresh on selection change, I'm doing this:
grid.SelectedRecordsChanged += (sender, e) => grid.Table.InvalidateSummary();

But this doesn't seem to be working.

Any ideas whether this it possible at all? If yes, then how?

Thanks.



1 Reply

VK Vinish Kumar K Syncfusion Team August 28, 2012 01:15 PM UTC

Hi Harshath,

Thank you for your interest in Syncfusion products.

Its possible, you can create a Summaries for GridGroupingControl.Here what i do to create summary. I hope this will be very useful for you.

// Setting summary -                                      
{

            GridSummaryColumnDescriptor sd1 = new GridSummaryColumnDescriptor();
            sd1.Name = "Net";
            sd1.DataMember = "Net";
            sd1.DisplayColumn = "Net";
            sd1.Format = "{Total}";
            sd1.SummaryType = SummaryType.Custom;

            this.gridGroupingControl.TableDescriptor.Columns.IsModified = true;

            this.gridGroupingControl.TableDescriptor.SummaryRows.Add(new GridSummaryRowDescriptor("Row 1", "Total", new GridSummaryColumnDescriptor[] { sd1 }));

       this.gridGroupingControl.TableDescriptor.Appearance.AnySummaryCell.HorizontalAlignment = GridHorizontalAlignment.Center;
            this.gridGroupingControl.TableDescriptor.Appearance.AnySummaryCell.BackColor = Color.FromArgb(218, 234, 255);
}

Then you can hook a SelectedRecordsChanged in your Grid.

Refer the following code this may useful. Its working.

private void gridGroupingControl_SelectedRecordsChanged(object sender, SelectedRecordsChangedEventArgs e)
        {
            if (gridGroupingControl.Table.SelectedRecords != null && gridGroupingControl.Table.SelectedRecords.Count != 0)
            {
                gridGroupingControl.Table.InvalidateSummary();
                gridGroupingControl.Table.InvalidateCounterBottomUp();
                gridGroupingControl.Refresh();
            }
        }


Please let me know if you have any further concerns.

Regards,
Vinish Kumar K.


Loader.
Up arrow icon