How to create barcodes in VB.NET RDLC local reports in Windows Forms application?
This guide provides a structured, step-by-step workflow for barcode generation and printing in local RDLC reports (Report Definition Language Client-Side) using the BarcodeLib RDLC Report Barcode Generator library.
It supports VB.NET Windows Forms Applications and VB.NET WPF Applications built on the .NET Framework.
RDLC Local Report Barcode Generator Library
QR Code, Data Matrix, Code 128, GS1, EAN/UPC. Unicode text encoding in VB.NET RDCL Local Report Windows application.
Step 1. Create a New VB.NET Windows Desktop Project
Open Visual Studio 2022 and select the Create a new project option.
In the project template selection window: Choose Windows Forms App (.NET Framework) (VB.NET)
Click Next to proceed.
Set the project name as BarcodeLibRDLCBarcodeWinFormsVbnetDemo.
Select your target .NET Framework version and complete project creation.
Step 2. Add Dependent Libraries and NuGet Packages
In the Solution Explorer, right-click the References node of the project.
Select Manage NuGet Packages from the context menu.
Switch to the Browse tab, set the package source to nuget.org.
Search for and install Microsoft.ReportingServices.ReportViewerControl.Winforms (latest stable version).
Manually add the BarcodeLib RDLC barcode library: BarcodeLib.Barcode.RDLCReports.dll to the project references.
Step 3. Implement Barcode Printing from a DataTable in RDLC Reports
3.1 Create and Configure a Typed DataSet (Data Source)
Right-click the VB.NET project in the Solution Explorer.
Select Add > New Item..., then add a DataSet file named DataSet1.xsd.
Open DataSet1.xsd in the designer, right-click the canvas and add a new DataTable (default name: DataTable1).
Add the first column: Name it Data, set the Data Type to System.String.
Add the second column: Name it Barcode, set the Data Type to System.Byte[].
Note: The Barcode column must use System.Byte[] data type. Other data types cannot render barcode images in the RDLC report.
3.2 Design the RDLC Report Template
Here we will build the report layout and bind the DataSet to the report control.
Add a new RDLC Report item to the project and name it Report1.rdlc.
Select Report1.rdlc in the Solution Explorer, set the Copy to Output Directory property to Copy if newer.
In the Report Designer, right-click Datasets and select Add Dataset.
In the Dataset Properties window:
Data source: Select DataSet1
Available datasets: Select DataTable1
Insert a Table control into the report design area.
Drag the Data and Barcode fields from the Report Data panel to the Table cells.
Insert an Image control into the Barcode column cell
Configure image control properties:
Image source: Select Database
Use this field: Select [Barcode]
MIME type: Select image/png
Adjust the table row height and column width to fit the barcode display size.
3.3 Integrate the ReportViewer Control into the VB.NET Form
ReportViewer is a dedicated control for rendering and displaying local RDLC reports in Windows Forms.
Double-click Form1.vb to open the designer, drag a ReportViewer control from the Toolbox to the form.
Bind the control to the report: Select BarcodeLibRDLCBarcodeWinFormsVbnetDemo.Report1.rdlc.
3.4 VB.NET Code-Behind Implementation (Replace the Default Code)
Right-click the form and select View Code to open the VB.NET code-behind file (Form1.vb).
Clear the default code in Form1.vb and use the following VB.NET code to generate barcodes, populate the DataTable, and bind data to the RDLC report.
ImportsSystem.Drawing.ImagingImportsBarcodeLib.BarcodeImportsBarcodeLib.Barcode.RDLCReportsImportsMicrosoft.Reporting.WinFormsPublicClassForm1PrivateSubForm1_Load(senderAsObject, eAsEventArgs) HandlesMyBase.Load' Prepare report data.DimdtAsNewDataTable()
dt.Columns.Add("Data", GetType(String))
dt.Columns.Add("Barcode", GetType(Byte()))
Dimsite1AsString="https://www.barcodelib.com"Dimsite2AsString="https://www.google.com"Dimsite3AsString="https://www.youtube.com"' Create data for the 1st row in the table.DimbarcodeAsNewLinearRDLC()
barcode.Type=BarcodeType.CODE128barcode.ResizeImage=Truebarcode.ImageWidth=400barcode.ImageHeight=200barcode.ImageFormat=BLImageFormat.PNGbarcode.Data=site1DimimgDataAsByte() =barcode.drawBarcodeAsBytes()
dt.Rows.Add(site1, imgData)
' Create data for the 2nd row in the table.barcode.Data=site2imgData=barcode.drawBarcodeAsBytes()
dt.Rows.Add(site2, imgData)
' Create data for the 3rd row in the table.barcode.Data=site3imgData=barcode.drawBarcodeAsBytes()
dt.Rows.Add(site3, imgData)
' Configure ReportMe.ReportViewer1.LocalReport.ReportPath="Report1.rdlc"Me.ReportViewer1.LocalReport.DataSources.Clear()
Me.ReportViewer1.LocalReport.DataSources.Add(NewReportDataSource("DataSet1", dt))
Me.ReportViewer1.RefreshReport()
EndSubEndClass
Step 4. Execute and Preview the RDLC Barcode Report
Now we run the VB.NET Windows Forms application and view the barcode report output.
Press the shortcut key Ctrl + F5 to build and run the VB.NET Windows Forms project.
The Windows application main window will load and render the RDLC report automatically.
Related Barcode Generating Guide for .NET RDLC Reports: