GridView Print Style - CheckBox Column

5 posts, 0 answers
  1. ShareDocs
    ShareDocs avatar
    76 posts
    Member since:
    Oct 2012

    Posted 14 Nov 2012 Link to this post

    Hello,

    Checkbox column displays as "True" or "False" when preforming print preview.
    Is there a way to display other values only on printing mode?
    For example:
    instead of true display + and instead of false display -

    Thanks.
  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 14 Nov 2012 Link to this post

    Hello,

    If you are using export to pdf for this, you should take a look at this documentation article.

    And for your specific case, you can register for the HTMLCellFormatting event and do the following:
    void exporter_HTMLCellFormatting(object sender, Telerik.WinControls.UI.Export.HTML.HTMLCellFormattingEventArgs e)
    {
        if (e.GridCellInfo.Value is bool)
        {
            var boolValue = (bool)e.GridCellInfo.Value;
            e.HTMLCellElement.Value = boolValue ? "+" : "-";
        }
    }

    If you have any other questions, please let me know.

    Best Regards,
    Emanuel Varga
    WinForms MVP
  3. UI for WinForms is Visual Studio 2017 Ready
  4. ShareDocs
    ShareDocs avatar
    76 posts
    Member since:
    Oct 2012

    Posted 14 Nov 2012 Link to this post

    Hello,

    I am using radGridView.PrintPreview function.
    In order to use the exporter, I need to export the grid to html file.
    Is there another solution for printing other values for boolean columns without saving a file?

    Thanks.
  5. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 14 Nov 2012 Link to this post

    Hello again,

    For this you need to register to the PrintCellFormatting event and do the following:
    private void grid_PrintCellFormatting(object sender, PrintCellFormattingEventArgs e)
    {
        if (e.Column is GridViewCheckBoxColumn && e.Row.Cells[e.Column.Index].Value is bool)
        {
            e.PrintCell.Text = ((bool)e.Row.Cells[e.Column.Index].Value) ? "+" : "-";
        }
    }

    If you have any other questions, please let me know.

    Best Regards,
    Emanuel Varga
    WinForms MVP
  6. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 19 Nov 2012 Link to this post

    Hello guys,

    Thank you both for writing.

    Lior, Emanuel's solution is the right way to go in this situation. I am marking his post as answer in order to allow other users searching for this information to easily find it. You can read more on customizing the result of printing a grid in our online documentation - RadGridView Printing. 

    Should you have further questions, do not hesitate to write back.
     
    All the best,
    Ivan Petrov
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Back to Top
UI for WinForms is Visual Studio 2017 Ready