GridView ExportHierarchy for Multiple Child Templates?

4 posts, 0 answers
  1. Mark
    Mark avatar
    8 posts
    Member since:
    Jun 2011

    Posted 04 May 2012 Link to this post

    Hello,

    I have a RadGridView that contains 3 child templates in it. So when you expand each row, there are 3 tabs that you can view the data for each child template by clicking on each tab.

    In my export code, i have the exporter.ExportHierarchy = true; for each export function. However, when i go to export the gridview to CSV / Excel / HTML / PDF, it appears that it can only export the first child template hierarchical grid data. It does not export all 3.

    My question - Can the data for ALL child templates be exported using the CSV / Excel / HTML and/or PDF exporter commands?

    Please let me know if this is possible, as right now it is only exporting the first child template.

    If this is not possible to export all 3 child templates, is it possible to remove certain child templates before exporting so that i can provide my user with options on what child template they want to export?

    Your help in this matter would be greatly appreciated, thanks!
  2. Ivan Petrov
    Admin
    Ivan Petrov avatar
    705 posts

    Posted 09 May 2012 Link to this post

    Hi Mark,

    Thank you for writing.

    Currently the export to Excel feature in RadGridView can export only the first template in MasterTemplate.Templates collection. You can, indeed, remove the unneeded templates in order to give your users a choice what to export and then add them back. Here is a code snippet which demonstrates how:

    GridViewTemplate templateToExport = this.radGridView1.MasterTemplate.Templates[1];
     
    List<GridViewTemplate> templates = new List<GridViewTemplate>();
     
    foreach (GridViewTemplate template in this.radGridView1.MasterTemplate.Templates)
    {
      if (template != templateToExport)
      {
        templates.Add(template);
      }
    }
     
    foreach (GridViewTemplate template in templates)
    {
      this.radGridView1.MasterTemplate.Templates.Remove(template);
    }
     
    ExportToExcelML exporter = new ExportToExcelML(this.radGridView1);
    exporter.ExportHierarchy = true;              
    exporter.RunExport(filePath);
     
    foreach (GridViewTemplate template in templates)
    {
      this.radGridView1.MasterTemplate.Templates.Add(template);
    }

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

    Greetings,
    Ivan Petrov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. Doug
    Doug avatar
    10 posts
    Member since:
    Dec 2011

    Posted 18 May 2012 Link to this post

    I am exporting a GridView that contains 2 child templates. However, I am not using the ExportToExcelML to perform the export. I am using Interop.Excel.

    The two child templates are displayed at the same hierarchical level. Currently, I am using "foreach" to step through each row in the parent template and write its data to the Excel sheet.

    I'm having trouble stepping through the related rows in each child template once I have the GridViewRowInfo of the parent row inside the "foreach". I can't seem to find an efficient way to access the rows of each template that directly relate to the current parent row. The ChildRows collection only seems to contain the rows of the first template.

    Is there a built-in method or an elogant approach I could use to step through the child rows of each child template?

    My current setup is as follows:
    foreach (GridViewRowInfo row in gridView.Rows)
    {
       //Write parent row data to Excel sheet
     
       //Access each child template either with a loop or explicitly
       //Step through child template's rows and write the row data to the Excel sheet
    }

  4. Ivan Petrov
    Admin
    Ivan Petrov avatar
    705 posts

    Posted 23 May 2012 Link to this post

    Hi Doug,

    Thank you for writing.

    You can use the following code snippet to access the child views of a hierarchy rows:
    foreach (GridViewHierarchyRowInfo parentRow in this.radGridView1.Rows)
    {
      //Export row...
      foreach (GridViewInfo view in parentRow.Views)
      {
        //Export child templates...
        foreach (GridViewRowInfo row in view.ChildRows)
        {
          //Export child template rows...
        }
      }
    }
    I hope this will be useful for you. If you have further questions, I would be glad to help.
     
    Kind regards,
    Ivan Petrov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top