aggregate gridview cells

4 posts, 0 answers
  1. Alden
    Alden avatar
    2 posts
    Member since:
    Oct 2015

    Posted 20 Oct 2015 Link to this post

    Hi, I am currently using the trial version of Telerik Winform and I would like a code example on how to aggregate cells in my gridview with the following two examples.

     Example1:

    1997     a                                           a

    1997     b  ->  becomes  ->   1997     b

    1997     c                                            c

     Where 1997 becomes a vertical aggregate field.

    Example2:

    1997     1997     1997 ->               1997

    a            b           c               a          b          c

    Where 1997 becomes a horizontal aggregate field

  2. Hristo
    Admin
    Hristo avatar
    714 posts

    Posted 22 Oct 2015 Link to this post

    Hello Alden,

    Thank you for writing.

    You can achieve the desired result by handling the CellFormatting event of your RadGridView and for certain cells having set their Text property to an empty string. Additionally you could also set their DrawBorder property to false. Please check my code snippet below: 
    private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        if (e.CellElement.RowIndex > 0 && e.CellElement.ColumnInfo.Name == "1997")
        {
            e.CellElement.Text = "";
            e.CellElement.DrawBorder = false;
        }
    }

    More information is available in the following documentation article: Formatting Cells. Additionally I am sending you a screenshot of the result on my end.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Alden
    Alden avatar
    2 posts
    Member since:
    Oct 2015

    Posted 23 Oct 2015 Link to this post

    Hi Hristo, thanks a lot for the reply! I meant to have that aggregated output for the Excel export. Since the Telerik Excel export accepts a radgridview I thought I need to aggregate it before I can export it like the Pivotgrid. But anyway, does the result for your radgridview aggregate carries on to the Excel export? Thanks again!
  5. Hristo
    Admin
    Hristo avatar
    714 posts

    Posted 28 Oct 2015 Link to this post

    Hello Alden,

    Thank you for writing back.

    The solution I last sent you concerns the visual appearance in RadGridView and exporting it as is will not aggregate the results in Excel. In order to achieve this task, you would need to handle the WorkBookCreated event of your SpreadExportRenderer instance. Then thanks to our SpreadProcessing library you can merge the cells having equal value of your column. Please check my snippet below: 
    private void radButton1_Click(object sender, EventArgs e)
    {
        GridViewSpreadExport spreadExporter = new GridViewSpreadExport(this.radGridView1);
        spreadExporter.ExportVisualSettings = true;
        SpreadExportRenderer exportRenderer = new SpreadExportRenderer();
        exportRenderer.WorkbookCreated += exportRenderer_WorkbookCreated;
        spreadExporter.RunExport(@"..\..\\exportedFile.xlsx", exportRenderer);
    }
     
    private void exportRenderer_WorkbookCreated(object sender, WorkbookCreatedEventArgs e)
    {
        CellIndex start = new CellIndex(1, this.radGridView1.Columns.IndexOf("1997"));
        CellIndex end = new CellIndex(this.radGridView1.Rows.Count, this.radGridView1.Columns.IndexOf("1997"));
     
        (e.Workbook.Sheets[0] as Worksheet).Cells[start, end].Merge();
    }

    More information is available in the following documentation resources: RadGridView | SpreadExport, SpreadProcessing | Merge and Unmerge Cells.

    I hope this helps. Should you have further questions please do not hesitate to write back. 

    Regards,
    Hristo Merdjanov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top