GS1 - DataBar

  • 2 minutes to read

The GS1 DataBar barcode is based on a family of symbols often used in the GS1 DataBar Coupon (coupon codes are commonly used in retail).

Barcode - GS1 DataBar

Refer to the following article for more details: GS1 DataBar.

Add the Bar Code to a Report

  1. Drag the XRBarCode item from the DX.20.2: Report Controls tab and drop it onto the report.

  2. Set the XRBarCode control’s Symbology property to DataBar (an object of the DataBarGenerator type).

  3. Specify common barcode properties and properties specific to GS1 DataBar.

Specific Properties

  • FNC1Substitute

    Specifies the symbol (or set of symbols) in the barcode text that are replaced with the FNC1 functional character when the barcode’s bars are drawn.

  • Type

    Gets or sets the type of the GS1 DataBar barcode.

  • SegmentsInRow

    Gets or sets the number of data segments per row in the Expanded Stacked type of the GS1 DataBar barcode.

Runtime Example

The following code creates the GS1 DataBar barcode and specifies its properties.

NOTE

The complete sample project is available in the following repository: https://github.com/DevExpress-Examples/how-to-add-a-bar-code-to-a-report-e167.

using System;
using System.Collections.Generic;
using System.Drawing.Printing;
using System.Windows.Forms;
using DevExpress.XtraPrinting.BarCode;
using DevExpress.XtraReports.UI;
// ...
public XRBarCode CreateDataBarGS1BarCode(string BarCodeText) {
    // Create a bar code control.
    XRBarCode barCode = new XRBarCode();

    // Set the bar code's type to GS1 DataBar.
    barCode.Symbology = new DataBarGenerator();

    // Adjust the bar code's main properties.
    barCode.Text = BarCodeText;
    barCode.Width = 250;
    barCode.Height = 160;

    // Adjust the properties specific to the bar code type.
    ((DataBarGenerator)barCode.Symbology).FNC1Substitute = "#";
    ((DataBarGenerator)barCode.Symbology).SegmentsInRow = 4;
    ((DataBarGenerator)barCode.Symbology).Type = DataBarType.ExpandedStacked;

    return barCode;
}

To add the XRBarCode to a report band, handle the report’s BeforePrint event.

using System.Drawing.Printing;
// ...

private void XtraReport1_BeforePrint(object sender, PrintEventArgs e) {
    this.Detail.Controls.Add(CreateDataBarGS1BarCode("012345678"));
}