Skip to main content
A newer version of this page is available. .

Adding Bar Codes to Reports

  • 3 minutes to read

This document describes how to use bar codes in reports, lists the main properties required to create bar codes of different types, and explains how to prevent errors that are most frequently encountered when creating bar codes.

The bar code generator that is provided by XtraReports is also available as a standalone Windows Forms control: BarCodeControl.

This document consists of the following sections.

Bar Code Options

To insert a bar code into a report, drag an XRBarCode control item from the DX.17.2: Report Controls Toolbox tab and drop it onto the report.

toolbox-add-bar-code

After creating the bar code, click its smart tag to access its main properties.

  • To specify the bar code type (symbology), use the XRBarCode.Symbology property.

    bar-code-symbology-smart-tag

    After specifying the symbology, you can customize the type-specific options of the bar code, which are listed in the Properties window under the Symbology property.

    bar-code-symbology-options

    Tip

    In code, use the Symbology property to assign the bar code generator (the BarCodeGeneratorBase class descendant) that is appropriate to this bar code type.

  • To supply the data that a bar code should encode, use the XRBarCode.BinaryData property.
  • To specify the bar width (a bar code’s resolution), use the following options:

    • Automatically calculate the bar width according to a bar code’s dimensions by enabling the XRBarCode.AutoModule property;
    • Provide a fixed bar width value using the XRBarCode.Module property.
  • The following are some additional bar code options:

Common Errors

The following section explains how to work around the most frequently encountered errors related to the incorrect use of bar codes.

  • The following error message is shown in place of the bar code if the control’s dimensions are too small to fit the bar code with its specified resolution.

    Barcode - Using Barcodes 3

    To get rid of this error, enable the XRBarCode.AutoModule property and/or increase the bar code’s dimensions.

  • The following exception appears when the data supplied to a bar code contains characters that are not supported by this bar code type.

    Barcode - Using Barcodes 4

    To avoid this error, supply data that applies to a particular bar code specification.

After specifying bar code settings, you can make sure that the resulting bar code will be properly rendered in a document by calling the XRBarCode.Validate method (e.g., in the XRControl.BeforePrint event handler).

See Also