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

GridView ExportHierarchy for Multiple Child Templates?

3 Answers 214 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 04 May 2012, 08:46 PM
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!

3 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 09 May 2012, 04:37 PM
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 >>
0
Doug
Top achievements
Rank 1
answered on 18 May 2012, 10:42 PM
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
}

0
Ivan Petrov
Telerik team
answered on 23 May 2012, 02:11 PM
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 >>
Tags
GridView
Asked by
Mark
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Doug
Top achievements
Rank 1
Share this question
or