This is a migrated thread and some comments may be shown as answers.

Sum of summary rows items

7 Answers 428 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mohamed
Top achievements
Rank 1
Mohamed asked on 29 Nov 2014, 09:10 PM
I'm using a dataview which contains master template and child template. for child row set i have a summary row which contains the totals of Column X. I need to add a summary row to the master template which contains the sum of the children summary rows (sum of sums of column X).

7 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Dec 2014, 04:41 PM
Hello Mohamed,

Thank you for writing.

In order to achieve your goal you can add a summary row to the master template for a specific column. Then, you can subscribe to the RadGridView.GroupSummaryEvaluate event and set the GroupSummaryEvaluationEventArgs.FormatString argument to the manually calculated sum of all X values from the child rows:
private void radGridView1_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
{
    if (sender is MasterGridViewTemplate)
    {
        decimal sum = 0;
        foreach (GridViewHierarchyRowInfo masterRow in this.radGridView1.Rows)
        {
            foreach (GridViewRowInfo childRow in masterRow.ChildRows)
            {
                sum += (decimal)childRow.Cells["UnitPrice"].Value;
            }
        }
        e.FormatString = "Sum of all child rows: "+sum;
    }
}

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Kalai
Top achievements
Rank 1
Veteran
answered on 23 Oct 2018, 10:55 AM

Additional information: Unable to cast object of type 'Telerik.WinControls.UI.GridViewDataRowInfo' to type 'Telerik.WinControls.UI.GridViewHierarchyRowInfo'.

I Have this error. 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Oct 2018, 11:05 AM
Hello, Kalai, 

According to the error you are facing, I suppose that you don't use a hierarchical grid. I have attached my sample project for your reference.

If you are sill experiencing any further difficulties, feel free to submit a support ticket where you can provide your sample project and additional information about the precise case. Thus, our support staff will gladly assist you.

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Kalai
Top achievements
Rank 1
Veteran
answered on 23 Oct 2018, 12:04 PM

Again I Have Same Error

Can you tell if another way to find the sum of grouped Coulmns in telerik gridview?

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Oct 2018, 01:01 PM
Hello, Kalai, 

Before running the attached sample project, it is necessary to add the references required in the application. Please make sure that you have added the following dlls:
- Telerik.WinControls
- Telerik.WinControls.GridView
- Telerik.WinControls.UI
- TelerikCommon

After running the application you are not supposed to obtain this error because the form contains a RadGridView with automatically generated hierarchy. I have modified the code snippet in order to ensure that the iterated rows are only GridViewHierarchyRowInfos:

private void radGridView1_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
{
    if (sender is MasterGridViewTemplate)
    {
        decimal sum = 0;
        foreach (GridViewRowInfo masterRow in this.radGridView1.Rows)
        {
            GridViewHierarchyRowInfo hierarchyRow = masterRow as GridViewHierarchyRowInfo;
            if (hierarchyRow == null)
            {
                continue;
            }
            foreach (GridViewRowInfo childRow in masterRow.ChildRows)
            {
                sum += (decimal)childRow.Cells["UnitPrice"].Value;
            }
        }
        e.FormatString = "Sum of all child rows: " + sum;
    }
}

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Kalai
Top achievements
Rank 1
Veteran
answered on 24 Oct 2018, 05:40 AM

Can You tell How to Export RadGridView to Excel with Visual Settings

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Oct 2018, 07:52 AM
Hello, Kalai, 

GridViewSpreadExport utilizes our RadSpreadProcessing library to export the content of RadGridView to xlsx, csv, pdf and txt formats. The ExportVisualSettings property allows you to export the visual settings (themes) to the exported file. RadGridView will also export all formatting to the Excel file. The column width and row height will also be matched in the exported file.

The article will explain in detail the SpreadExport abilities and will demonstrate how to use it: https://docs.telerik.com/devtools/winforms/gridview/exporting-data/spread-export

I hope it suits your scenario. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Mohamed
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Kalai
Top achievements
Rank 1
Veteran
Share this question
or