GridViewPdfExport RadDropDownListEditor exports ValueMember

5 posts, 0 answers
  1. Simon
    Simon avatar
    32 posts
    Member since:
    Aug 2011

    Posted 30 Jan 2018 Link to this post

    Hi

    I'm using GridViewPdfExport to export a radGrid to pdf. I have a column that is set up to use a mixture of radTextBoxEditors, RadDropDownListEditors and RadDateTimeEditors depending on the data in the cell. The RadDropDownList editors each have different data sources but each uses an integer ID field as the valueMember and a text field as the displayMember. When I export to pdf, the cells that use a RadDropDownListEditor export the valueMember and not the displayMember. How do I get them to export the DisplayMember? 

    I can see that I'd need to use the exportToPdfCellFormatting event but I don't know how to:
     - work out whether the cell uses a RadDropDownListEditor (I can use logic based on the values of other cells in the row but if I do that, I can see it leading to a bug at some point in the future when new logic is added to the form. It would be much safer if I can write the equivalent of "If the cell uses a RadDropDownListEditor")
     - get the DisplayMember value
  2. Simon
    Simon avatar
    32 posts
    Member since:
    Aug 2011

    Posted 30 Jan 2018 in reply to Simon Link to this post

    Also how do I change the color of a cell in the exported pdf? I've tried using the following code in the exportToPDFCellFormatting event but it doesn't do anything:

                        e.CellElement.BackColor = Color.Red
                        e.CellElement.BackColor2 = Color.Red
                        e.CellElement.BackColor3 = Color.Red
                        e.CellElement.BackColor4 = Color.Red

  3. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3089 posts

    Posted 30 Jan 2018 Link to this post

    Hello, Simon,

    Thank you for writing.  

    If you use GridViewComboBoxColumn, the specified DisplayMember field will be exported in the GridViewPdfExport:

    private void RadForm1_Load(object sender, EventArgs e)
    {
        this.productsTableAdapter.Fill(this.nwindDataSet.Products);
     
        GridViewComboBoxColumn comboColumn = new GridViewComboBoxColumn("Products");
        comboColumn.DataSource = this.productsBindingSource;
        comboColumn.ValueMember = "ProductID";
        comboColumn.DisplayMember = "ProductName";
        comboColumn.Width = 200;
        this.radGridView1.Columns.Add(comboColumn);
     
        for (int i = 1; i < 10; i++)
        {
            this.radGridView1.Rows.Add(i);
        }
    }
     
    private void radButton1_Click(object sender, EventArgs e)
    {
        Telerik.WinControls.Export.GridViewPdfExport pdfExporter = new Telerik.WinControls.Export.GridViewPdfExport(this.radGridView1);
        string fileName = @"..\..\ExportedData" + DateTime.Now.ToLongTimeString().Replace(":", "_") ;
        pdfExporter.RunExport(fileName, new Telerik.WinControls.Export.PdfExportRenderer());
        Process.Start(fileName + ".pdf");
    }



    However, if you use different column types to store the numeric values, note that you can add a hidden text column that holds the respective text value. Then, before exporting you can hide the numeric column and show the hidden one in order to export the desired data. Then, restore the columns visibility as before.

    I hope this information helps. Should you have further questions I would be glad to help. 
     
     Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  4. Simon
    Simon avatar
    32 posts
    Member since:
    Aug 2011

    Posted 30 Jan 2018 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thanks Dess

    I have a few more questions:

    1. The grid rows autosize so that they're big enough to show all data. The text in some of the cells wraps and takes up multiple lines. When I export to pdf, each row is only one line of text high, so the remaining text gets chopped off. How can I make the rows in the pdf big enough to show all of the text for the rows where the text wraps over multiple lines?

    2. The grid has some rows that have no text in them at all, that have a blue backcolor and that are only about a quarter the height of a standard row. These are used as a visual divider between sections. In the exported pdf, these rows are standard height and standard backcolor. I've tried changing cell backcolor and rowheight in the exportToPDFCellFormatting event but it has no effect. How can I change the cell backcolor and rowheight in the exported pdf?

  5. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3089 posts

    Posted 31 Jan 2018 Link to this post

    Hello, Simon,  

    Thank you for writing back. 

    1. In order to wrap the text in the exported pdf file you can subscribe to the GridViewPdfExport.CellFormatting event and set the PdfExportCellFormattingEventArgs.CellElement.TextWrap property to true
    private void radButton1_Click(object sender, EventArgs e)
    {
        Telerik.WinControls.Export.GridViewPdfExport pdfExporter = new Telerik.WinControls.Export.GridViewPdfExport(this.radGridView1);
        string fileName = @"..\..\ExportedData" + DateTime.Now.ToLongTimeString().Replace(":", "_") ;
        pdfExporter.CellFormatting += pdfExporter_CellFormatting;
        pdfExporter.RunExport(fileName, new Telerik.WinControls.Export.PdfExportRenderer());
        Process.Start(fileName + ".pdf");
    }
     
    private void pdfExporter_CellFormatting(object sender, Telerik.WinControls.Export.PdfExportCellFormattingEventArgs e)
    {
        e.CellElement.TextWrap = true;
    }



    2. I tried to add a row with empty cells in order to achieve the described dividers. The row's height is less than 10px because the RadGridView.AutoSizeRows property is set to true. The dividers have a similar height in the exported pdf file as it is demonstarted below. I have attached my sample project for your reference. 



    Could you please specify the exact steps how to reproduce the problem?  Feel free to modify it in a way to reproduce the experienced issue and get back to me with it so I can investigate the precise case. Thank you in advance. 

    I am looking forward to your reply.

     Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top