We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Summing by unique categories

Thread ID:

Created:

Updated:

Platform:

Replies:

146449 Aug 4,2019 04:23 PM UTC Aug 5,2019 02:03 PM UTC WinForms 1
loading
Tags: GridGroupingControl
Travis Chambers
Asked On August 4, 2019 04:23 PM UTC

Hi ,

I need to be able to show a financial sum for unique values in a category in a regular gridcontrol next to the ggc with the source data (populated by a datatable).

For example, if I had a table like this:

Red    100
Red    500
Blue   200
Blue   120

I would need to display this in the gridcontrol:

Red  600
Blue  320

I would also need the grid control to automatically update the gridcontrol data to reflect any filters applied to the ggc.

Is there a built in method, or otherwise easy way to get this data from the ggc to the gridcontrol? If not, can I export only the filtered data from the ggc to a DataTable? If push comes to shove I could do a linq query on the exported tables, but that's probably less than ideal.

Thanks!


Arulpriya Ramalingam [Syncfusion]
Replied On August 5, 2019 02:03 PM UTC

Hi Travis, 
 
Thanks for using Syncfusion support. 
 
The GridGroupingControl does not has the built-in methods to populate the group summaries to a external grid or datatable. However, this can be achieved by adding a SummaryRow for the specified column and in the below provided sample, we have achieved your requirement with “sport” and “wins” column. In order to, get the sum value of the group, the GetSummary() method can be used and to get the grouped item, the Category property of the GridGroup can be used. Moreover, the grid does not update the values on demand when the record values are changed. In order to overcome this use case, the SourceListRecordChanged, RecordFilters.Changed (Dynamic/Normal filter) and CategorizedRecords (Excel Filter) events can be used to update the grid data. Please make use of the below code and sample, 
 
Code example 
 
internal void LoadGridData() 
{ 
    gridcontrol1.RowCount = gridGroupingControl1.Table.TopLevelGroup.Groups.Count; 
    int i = 1; 
    foreach (GridGroup gridGroup in gridGroupingControl1.Table.TopLevelGroup.Groups) 
    { 
        double sum = (gridGroup.GetSummary(0) as DoubleAggregateSummary).Sum; 
        string category = gridGroup.Category.ToString(); 
        gridcontrol1[i, 1].CellValue = category; 
        gridcontrol1[i, 2].CellValue = sum; 
        i++; 
    } 
} 
 
 
Regards, 
Arulpriya 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon