I need to export a hierarchical grid to pdf, but I can't seem to get the child data into the pdf.
I found examples for using the ElementExporting and ElementExported events, but when I call .ExportToPdf() those events do not get thrown.
http://www.telerik.com/forums/export-hierarchical-grid-b2daf443a4fc
Some threads also mention following this article to make a Table, but I can't figure out what making this table has to do with ExportToPdf.
http://docs.telerik.com/devtools/silverlight/controls/radrichtextbox/document-elements/features-tables.html
Code:
My grid's HierarchyChildTemplate is defined in the View's resources.
private void Save()
{
View.grd_Results.ElementExporting -= this.ElementExporting;
View.grd_Results.ElementExporting += this.ElementExporting;
View.grd_Results.ElementExported -= this.ElementExported;
View.grd_Results.ElementExported += this.ElementExported;
string extension = "pdf";
SaveFileDialog dialog = new SaveFileDialog()
{
DefaultExt = extension,
Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Pdf"),
FilterIndex = 1
};
if (dialog.ShowDialog() == true)
{
GridViewPdfExportOptions opt = new Telerik.Windows.Controls.GridViewPdfExportOptions()
{
ShowColumnFooters = false,
ShowColumnHeaders = true,
ShowGroupFooters = true,
PageOrientation = PageOrientation.Portrait,
ExportDefaultStyles = true,
AutoFitColumnsWidth = true,
Items = Results
};
using (Stream stream = dialog.OpenFile())
{
View.grd_Results.ExportToPdf(stream, opt); //ElementExporting && ElementExported do not get thrown
}
View.busy_PDFView.IsBusy = false;
}
}
private void ElementExporting(object sender, GridViewElementExportingEventArgs e)
{
if (e.Element == ExportElement.HeaderRow)
{
var htmlVisualExportParameters = e.VisualParameters as GridViewHtmlVisualExportParameters;
if (htmlVisualExportParameters != null)
{
htmlVisualExportParameters.FontWeight = FontWeights.Bold;
}
}
}
private void ElementExported(object sender, GridViewElementExportedEventArgs e)
{
if (e.Element == ExportElement.Row)
{
IncentiveUnitMock obj = e.Context as IncentiveUnitMock;
var template = View.LayoutRoot.Resources["ChildTableTemplate"] as DataTemplate;
var grid = template.LoadContent() as RadGridView;
grid.DataContext = obj;
GridViewPdfExportOptions opt = new GridViewPdfExportOptions()
{
ShowColumnFooters = false,
ShowColumnHeaders = true,
ShowGroupFooters = true,
PageOrientation = PageOrientation.Portrait,
ExportDefaultStyles = true,
AutoFitColumnsWidth = true,
Items = obj.Incentives
};
var stream = new MemoryStream();
grid.ExportToPdf(stream, opt);
var subExport = new StreamReader(stream).ReadToEnd();
e.Writer.Write(subExport);
}
}
How can I export the full table and child tables to pdf?