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

Print grid with barcodes in grid cell

2 Answers 37 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tomas
Top achievements
Rank 1
Veteran
Tomas asked on 01 Apr 2021, 05:55 PM

Hello, does anybody have experience with printing gridview where one of the columns contains strings formatted with barcode font?

I have three columns in the grid and my goal is to print gridview where one column is formatted with barcode font and the rest of columns are formatted with different font. I am able to set the barcode font to all datacells. It seems that GridPrintStyle does not support such granular columns formatting.

private void btnPrintDispatchedContainers_Click(object sender, EventArgs e)
{
    GridPrintStyle style = new GridPrintStyle();
    style.FitWidthMode = PrintFitWidthMode.NoFit;
    style.PrintGrouping = true;
    style.PrintHeaderOnEachPage = true;
    style.PrintHiddenColumns = false;
    Font barcodeFont = new Font("Code 128", 20f, FontStyle.Regular);
    Font groupRowFont = new Font("Segoe UI", 12f, FontStyle.Bold);
    style.CellFont = barcodeFont;
    style.GroupRowFont = groupRowFont;
    rgvDispatchedContainers.PrintStyle = style;
    rgvDispatchedContainers.Print();
}

 

Any thoughts will be appreciated.

2 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 05 Apr 2021, 10:03 AM

Hello, Tomas, 

RadGridView offers the PrintCellFormatting event. It allows the developer to customize the print output for each individual cell. Thus, you can assign any specific font for the barcode cells:

        private void radGridView1_PrintCellFormatting(object sender, PrintCellFormattingEventArgs e)
        {
            if (e.Column.Name == "Barcode")
            {
                e.PrintCell.Font = barcodeFont;
            }
            else
            {
                e.PrintCell.Font = groupRowFont;
            }
        }

        Font barcodeFont = new Font("Code 128", 20f, FontStyle.Regular);
        Font groupRowFont = new Font("Segoe UI", 12f, FontStyle.Bold);

More information about the events and customizations for the print document is available in the following help article:
https://docs.telerik.com/devtools/winforms/controls/gridview/printing-support/events-and-customization

Off topic, I would suggest you a possible solution for the case with a barcode cell. RadGridView offers a convenient way to create custom cells. You can host a barcode element and display the barcode value in a more user-friendly way. A sample approach for creating custom cells is demonstrated here:

https://docs.telerik.com/devtools/winforms/controls/gridview/cells/creating-custom-cells 

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Tomas
Top achievements
Rank 1
Veteran
answered on 06 Apr 2021, 10:33 AM

Hello Dess,

many thanks for advice. The event PrintCellFormatting that s exactly what I was looking for. I did workaround and printed cell by cell. I am going to implement PrintCellFormatting first, looks much easier ;).

Cheers

Tags
GridView
Asked by
Tomas
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Tomas
Top achievements
Rank 1
Veteran
Share this question
or