Sum of summary rows items

8 posts, 0 answers
  1. Mohamed
    Mohamed avatar
    1 posts
    Member since:
    Oct 2014

    Posted 29 Nov 2014 Link to this post

    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).
  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3568 posts

    Posted 03 Dec 2014 Link to this post

    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.

     
  3. Kalai
    Kalai avatar
    4 posts
    Member since:
    Oct 2018

    Posted 23 Oct 2018 in reply to Dess | Tech Support Engineer, Sr. Link to this post

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

    I Have this error. 

  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3568 posts

    Posted 23 Oct 2018 Link to this post

    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.
  5. Kalai
    Kalai avatar
    4 posts
    Member since:
    Oct 2018

    Posted 23 Oct 2018 in reply to Kalai Link to this post

    Again I Have Same Error

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

  6. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3568 posts

    Posted 23 Oct 2018 Link to this post

    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.
  7. Kalai
    Kalai avatar
    4 posts
    Member since:
    Oct 2018

    Posted 24 Oct 2018 in reply to Dess | Tech Support Engineer, Sr. Link to this post

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

     

  8. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3568 posts

    Posted 24 Oct 2018 Link to this post

    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.
Back to Top