Exporting Parent items and Child

7 posts, 0 answers
  1. Christopher
    Christopher avatar
    4 posts
    Member since:
    Jun 2013

    Posted 17 Jul 2013 Link to this post

    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.
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 17 Jul 2013 Link to this post

    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 >>
  3. Christopher
    Christopher avatar
    4 posts
    Member since:
    Jun 2013

    Posted 17 Jul 2013 Link to this post

    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);
        }
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 17 Jul 2013 Link to this post

    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 >>
  5. Christopher
    Christopher avatar
    4 posts
    Member since:
    Jun 2013

    Posted 17 Jul 2013 Link to this post

    Yes. I will do that in case I run into any issues.

    Thanks again!
  6. Christopher
    Christopher avatar
    4 posts
    Member since:
    Jun 2013

    Posted 17 Jul 2013 Link to this post

    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?
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 17 Jul 2013 Link to this post

    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 >>
Back to Top