Summaries for each group in RadGridView

2 posts, 0 answers
  1. Bryan
    Bryan avatar
    4 posts
    Member since:
    Jul 2014

    Posted 10 Feb Link to this post

    It seems that I cannot display the exact sum of each group in the radGridView.

    I want is to add the sum of the Column A group and the sum of the Column B group belonging to group A,

    respectively, and the total at the bottom.

    If I want to implement what I want C#, I want to know how to implement it.

    I want you to show me how useful RadGridView is.

    Please refer to my attached file.

      

  2. Nadya
    Admin
    Nadya avatar
    389 posts

    Posted 13 Feb Link to this post

    Hello Bryan,

    If you have summary rows in a grouped RadGridView you can use the following properties in order to display the sum of total groups as well as the sum of each group:

    • ShowTotals - Indicate whether total summary rows are visible in a grouping.
    • ShowSubTotals - indicates whether summary rows will be shown for each group.
    • ShowParentGroupSummaries - Indicating whether parent group summary rows are visible in a grouping.

    You can find below a sample code snippet which result is demonstrated in the attached picture:

    public RadForm1()
    {
        InitializeComponent();
    
        DataTable dt = new DataTable();
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("Color", typeof(Color));
        dt.Columns.Add("Value", typeof(decimal));
    
        dt.Rows.Add("AA", Color.Red, 2);
        dt.Rows.Add("AA", Color.Red, 5);
        dt.Rows.Add("AA", Color.Red, 3);
        dt.Rows.Add("AA", Color.Green, 4);
        dt.Rows.Add("AA", Color.Green, 6);
        dt.Rows.Add("AA", Color.Green, 2);
        dt.Rows.Add("AA", Color.Blue, 7);
        dt.Rows.Add("AA", Color.Blue, 3);
        dt.Rows.Add("BB", Color.Red, 6);
        dt.Rows.Add("BB", Color.Red, 9);
        dt.Rows.Add("BB", Color.Green, 2);
        dt.Rows.Add("BB", Color.Green, 2);
        dt.Rows.Add("BB", Color.Blue, 4);
        dt.Rows.Add("BB", Color.Blue, 3);
        this.radGridView1.DataSource = dt;
        
        GridViewSummaryItem summaryItem = new GridViewSummaryItem();
        summaryItem.Name = "Value";
        summaryItem.AggregateExpression = "(Sum(Value))";
        GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
        summaryRowItem.Add(summaryItem);
        this.radGridView1.SummaryRowsBottom.Add(summaryRowItem);
    
       this.radGridView1.MasterTemplate.ShowTotals = true;
        this.radGridView1.MasterTemplate.ShowSubTotals = true;
        this.radGridView1.MasterTemplate.ShowParentGroupSummaries = true;
    }
    

    I hope this helps. Should you have any other questions do not hesitate to ask.

    Regards,
    Nadya
    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