Exporting Multiple Detail Grids

2 posts, 0 answers
  1. Josh Powell
    Josh Powell avatar
    2 posts
    Member since:
    Apr 2010

    Posted 19 Apr 2012 Link to this post

    I have a Silverlight RadGridView that has two separate RadGridViews inside of the RowDetailTemplate that I would like to export to excel.  Binding and displaying this data isn't a problem, but when I try to export the two detail grids they don't see to want to bind, and the detail tables will be empty in the spreadsheet.

    <telerik:RadGridView.RowDetailsTemplate>
      <DaTemplate>
     
    <StackPanel Orientation="Horizontal">
       <telerik:RadGridView x:Name="rgvTTDetail"  d:LayoutOverrides="Width"
               AutoGenerateColumns="False"  CanUserFreezeColumns="false" CanUserResizeColumns="False"
               HorizontalAlignment="Left" IsReadOnly="True" ItemsSource="{Binding TTOpenCases,
               Mode=OneWay}" Margin="10, 10, 0, 10" MaxHeight="300"
               RowIndicatorVisibility="Collapsed" ScrollViewer.VerticalScrollBarVisibility="Visible"
               ShowGroupPanel="False" VerticalAlignment="Top" telerik:StyleManager.Theme="Office_Silver">
     <telerik:RadGridView.Columns>
     <telerik:GridViewDataColumn Header="Test Engineer" DataMemberBinding="{Binding TTName}" Width="200" />
     <telerik:GridViewDataColumn Header="PIDs Opened" DataMemberBinding="{Binding PIDs_Opened}" Width="125" />
     </telerik:RadGridView.Columns>
    </telerik:RadGridView>
     <telerik:RadGridView x:Name="rgvQCDetail"  
                   d:LayoutOverrides="Width"
                   AutoGenerateColumns="False"  CanUserFreezeColumns="false" CanUserResizeColumns="False"
                   HorizontalAlignment="Left" IsReadOnly="True" ItemsSource="{Binding TestsExecuted, Mode=OneWay}" Margin="10, 10, 0, 10" MaxHeight="300"
                   RowIndicatorVisibility="Collapsed" ScrollViewer.VerticalScrollBarVisibility="Visible" ShowGroupPanel="False" VerticalAlignment="Top"                                                
                   telerik:StyleManager.Theme="Office_Silver">
         <telerik:RadGridView.Columns>
           <telerik:GridViewDataColumn Header="Test Engineer" DataMemberBinding="{Binding QCName}" Width="200" />
           <telerik:GridViewDataColumn Header="Tests Executed" DataMemberBinding="{Binding TestCasesExecuted}" Width="125" />
         </telerik:RadGridView.Columns>
    </telerik:RadGridView>
    </
    StackPanel>
    </DataTemplate>
    </telerik:RadGridView.RowDetailsTemplate>

    private void rgvTesterDetail_ElementExported(object sender, GridViewElementExportedEventArgs e)
       {
      if (e.Element == ExportElement.Row)
        {
       #region For a single grid, not in a StackPanel
       var grid = radGridView1.RowDetailsTemplate.LoadContent() as RadGridView;
       grid.DataContext = e.Context;
      
    e.Writer.Write(string.Format(@"<tr><td style=""background-color:#CCC;"" colspan=""{0}"">{1}</td></tr>", grid.Columns.Count, grid.ToHtml()));
     #endregion
      
     #region For dual grids, contained in a stack panel.  Although the dual grids won't export data.
     var grid = radGridView1.RowDetailsTemplate.LoadContent() as StackPanel;
      
     //grid.DataContext = e.Context;
      
     RadGridView[] grids = grid.ChildrenOfType<RadGridView>().ToArray();
     grids[0].DataContext = e.Context;
     grids[1].DataContext = e.Context;             
     e.Writer.Write("<tr><td style=\"background-color:#CCC;\" colspan=\"{0}\">{1}</td><td/><td style=\"background-color:#CCC;\" colspan=\"{2}\">{3}</td></tr>",
                     grids[0].Columns.Count, grids[0].ToHtml(),
                     grids[1].Columns.Count, grids[1].ToHtml());
     #endregion
     }

    So for some reason, it seems that when I involve the stack panel and two grids all of a sudden I can't bind to the data context anymore.  Am I missing something?  I haven't done much work with Silverlight so I'm not of the order of operations when binding, but everything seemed to be working when I had one detail grid with no stack panel.

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 20 Apr 2012 Link to this post

    Hi,

     Indeed, you will not be able to export the GridView inside the StackPanel using the specified code.
     What I can suggest is to implement the export of RowDetails as it is done at this online demo

    Greetings,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top