Products Technologies Demo Docs Blog Support Company

TX Barcode .NET: Implementing a Custom DataGridViewBarcodeCell

Barcodes are not only used in reports or forms. A typical application is the display of a specific cell value as a barcode in a DataGridView. One of our shipped samples show how to use TX Barcode .NET to implement a custom DataGridViewBarcodeCell. A DataGridView cell has two modes: An edit mode that is used when the user types in the value for the cell and a display mode that shows an image representation of the barcode. Open the sample project in Visual Studio and start the application. A…

TX Barcode .NET: Implementing a Custom DataGridViewBarcodeCell

Barcodes are not only used in reports or forms. A typical application is the display of a specific cell value as a barcode in a DataGridView. One of our shipped samples show how to use TX Barcode .NET to implement a custom DataGridViewBarcodeCell.

A DataGridView cell has two modes: An edit mode that is used when the user types in the value for the cell and a display mode that shows an image representation of the barcode.

Open the sample project in Visual Studio and start the application. A form with a DataGridView is shown. The column Barcode column shows barcode images.

Implementing a custom DataGridViewBarcodeCell

Use the mouse and click into one of the shown barcodes to select the cell. Click again to activate the edit mode of the custom cell. A text box is used as the editor in this case. Change the value to another numeric value such as "12345" and press return.

Implementing a custom DataGridViewBarcodeCell

The barcode is updated, the custom cell switches to the display mode and shows the updated image representation.

Implementing a custom DataGridViewBarcodeCell

In order to create the image representation, TX Barcode .NET provides a method that paints the actual barcode into a Graphics object. The following code shows how to use this method:

Bitmap bmp = new Bitmap(cellSize.Width, cellSize.Height);
ctl.BackColor = DataGridView.DefaultCellStyle.SelectionBackColor;
ctl.ForeColor = DataGridView.DefaultCellStyle.SelectionForeColor;

Graphics g = Graphics.FromImage(bmp);
ctl.PrintPaint(g, new Rectangle(0, 0, bmp.Width, bmp.Height));

Test this and many other samples and download the trial version today.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

Windows FormsGetting StartedTutorial

Windows Forms Tutorial: Create Your First Windows Forms C# Application

This tutorial shows how to create your first Windows Forms application with C# using TX Text Control .NET for Windows Forms in Visual Studio 2022.


ASP.NETASP.NET CoreMailMerge

How to Mail Merge MS Word DOCX Documents in ASP.NET Core C#

Mail merge is the process of merging data, such as Json or IEnumerable objects, into a template document, such as a DOC or DOCX file. This tutorial is a walkthrough of the steps necessary to…


AngularDocument EditorNode.js

Creating an Angular Document Editor Application with a Node.js WebSocket Server

This tutorial shows how to create an Angular application that uses the Document Editor with a Node.js WebSocket server.


ASP.NETASP.NET CoreMailMerge

Adding SVG Watermarks to Documents

This article shows how to add SVG images to document section headers that repeat automatically on each page. This watermark will be inserted vertically and horizontally centered on each section page.


ASP.NETASP.NET CoreMailMerge

Using MailMerge in ASP.NET Core 6 Web Applications

This article shows how to use the TX Text Control ASP.NET MailMerge class to merge templates with JSON data within a .NET 6 application in Visual Studio 2022.