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

Exporting Multiple Detail Grids

1 Answer 60 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Josh Powell
Top achievements
Rank 1
Josh Powell asked on 19 Apr 2012, 07:45 PM
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.

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 20 Apr 2012, 04:09 PM
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 >>

Tags
GridView
Asked by
Josh Powell
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or