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

Exporting Parent items and Child

6 Answers 138 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Christopher
Top achievements
Rank 1
Christopher asked on 17 Jul 2013, 12:53 PM
Hello. I have implemented a feature into my program where I can export the grid view to excel 2010, but only the parent items are exported, and not the child items. Is it possible to export both the parent and children items to excel in a hierarchy-like structure?

Thank you.

6 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 17 Jul 2013, 01:49 PM
Hi,

I am not sure how have you implemented the export feature, but as to hierarchy I would suggest you to work with the data items as demonstrated on the "Exporting RowDetails" WPF Demo. You can check the code inside "ElementExported' event handler.
Unfortunately the built-in Export method does not suggest hierarchical view of the exported data.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Christopher
Top achievements
Rank 1
answered on 17 Jul 2013, 01:51 PM
This is a code sample I found here in the forum. However, I'm using excel. I'm going to study this for a bit and see if it helps.

private void Button1_Click(object sender, RoutedEventArgs e)
{
    var saveDialog = new SaveFileDialog();
    if (saveDialog.ShowDialog() == true)
    {
        var stream = saveDialog.OpenFile();
        var streamWriter = new System.IO.StreamWriter(stream);
        streamWriter.Write(this.clubsGrid.ToCsv());
        streamWriter.Close();
        MessageBox.Show("Exported.");
    }
}
private void clubsGrid_ElementExported(object sender, GridViewElementExportedEventArgs e)
{
    if (e.Element == ExportElement.Row)
    {
        var template = this.LayoutRoot.Resources["HierarchyChildTemplate"as DataTemplate;
        var grid = template.LoadContent() as RadGridView;
        grid.DataContext = e.Context;
        var subExport = grid.ToCsv();
        e.Writer.Write(subExport);
    }
0
Dimitrina
Telerik team
answered on 17 Jul 2013, 02:06 PM
Hi,

Actually both the ways should work. If you experience problems with that, then would you please send us a demo project which we could check locally?
 

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Christopher
Top achievements
Rank 1
answered on 17 Jul 2013, 02:15 PM
Yes. I will do that in case I run into any issues.

Thanks again!
0
Christopher
Top achievements
Rank 1
answered on 17 Jul 2013, 03:45 PM
Thanks again for your help. I have managed to get the export working the way I wanted to, but I am curious as to whether I can export to excel with a child hierarchy included. Is this possible?
0
Dimitrina
Telerik team
answered on 17 Jul 2013, 04:30 PM
Hello,

There is not such an option. Still, what you can try is to
 additionally style the exported data. you can set the e.Styles dictionary with proper CSS values for text alignment and font of the cell's element when the ElementExporting is raised for the RadGridView. You can refer to the "Exporting" demo for an example.
 

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Christopher
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Christopher
Top achievements
Rank 1
Share this question
or