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

How to refer to the child gridview during export to PDF?

1 Answer 41 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alcide Burato
Top achievements
Rank 1
Alcide Burato asked on 19 May 2011, 09:10 AM
Hello,

Assuming I have a two levels hierarchical grid that is build dinamically where I don't know the number of the child grids and where the master template is different respect to the child template.

In order to export to pdf a gridview that contains child gridviews (hierarchical grid) I create an ExportToPDF object:

ExportToPDF exporter = new ExportToPDF(radGridView1);
exporter.HiddenColumnOption = Telerik.WinControls.UI.Export.HiddenOption.DoNotExport;
exporter.SummariesExportOption = SummariesOption.ExportAll;
exporter.FitToPageWidth = false;
exporter.Scale = 1;
exporter.FileExtension = "pdf";
exporter.TableBorderThickness = 1;
exporter.PdfExportSettings.EnableCopy = true;
exporter.HTMLCellFormatting += new Telerik.WinControls.UI.Export.HTML.HTMLCellFormattingEventHandler(exporter_HTMLCellFormatting);
exporter.ExportVisualSettings = true;
exporter.ExportHierarchy = true;
exporter.PdfExportSettings.FontType = Telerik.Apoc.Render.Pdf.FontType.Embed;

I need to format the cell value in the case it is type Decimal so I have added a new handle for the HTMLCellFormatting event:

void exporter_HTMLCellFormatting(object sender, Telerik.WinControls.UI.Export.HTML.HTMLCellFormattingEventArgs e)
{
    if (radGridView1.Columns[e.GridColumnIndex].DataType == Type.GetType("System.Decimal"))
    {
     // Some code to manage the format
       //e.HTMLCellElement.Value = string.Format(ecc ecc)
    }
}

In this event handler I need to retrieve the DataType of the current column and this code works perfectly if the current cell e.HTMLCellElement belongs to the master template in the hierarchical order. But when the current cell belongs to a child template it seems there is no way to retrieve the cell's column datatype because there is no way to retrieve what child gridview the cell belongs just starting from the "e" object.

So my question is: is there a way to understand if the indexe.GridColumnIndex refers to the MasterTemplate or if it refers to the Child Template inside the exporter_HTMLCellFormatting ?

Thanks for any aid,
Alcide




1 Answer, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 25 May 2011, 05:35 AM
Hello Alcide Burato,

Thank you for writing.

In Q1 2011 SP1 (2011.1.11.419)  release we have added a new reference argument for the HTMLCellFormatting event. It allows to get the original grid's cell info and access its ViewTemplate. Please consider the following as example:

void exporter_HTMLCellFormatting(object sender, HTMLCellFormattingEventArgs e)
{
    GridViewTemplate ownerTemplate = e.GridCellInfo.ViewTemplate;
}

Hope this helps, let me know if you have any other questions.

All the best,
Martin Vasilev
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Tags
GridView
Asked by
Alcide Burato
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Share this question
or