# TX Barcode .NET: Implementing a Custom DataGridViewBarcodeCell

> TX Barcode .NET renders barcodes inside DataGridView cells through a custom DataGridViewBarcodeCell. The cell switches between an edit mode with text input and a display mode showing barcode images. The PrintPaint method draws the barcode content into a Graphics object for rendering.

- **Author:** Bjoern Meyer
- **Published:** 2013-06-07
- **Modified:** 2026-03-05
- **Description:** TX Barcode .NET renders barcodes inside DataGridView cells through a custom DataGridViewBarcodeCell. The cell switches between an edit mode with text input and a display mode showing barcode images. The PrintPaint method draws the barcode content into a Graphics object for rendering.
- **2 min read** (307 words)
- **Tags:**
  - Tutorial
- **Web URL:** https://www.textcontrol.com/blog/2013/06/07/tx-barcode-net-implementing-a-custom-datagridviewbarcodecell/
- **LLMs URL:** https://www.textcontrol.com/blog/2013/06/07/tx-barcode-net-implementing-a-custom-datagridviewbarcodecell/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2013/06/07/tx-barcode-net-implementing-a-custom-datagridviewbarcodecell/llms-full.txt

---

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](https://s1-www.textcontrol.com/assets/dist/blog/2013/06/07/a/assets/grid_barcode_1.webp "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](https://s1-www.textcontrol.com/assets/dist/blog/2013/06/07/a/assets/grid_barcode_2.webp "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](https://s1-www.textcontrol.com/assets/dist/blog/2013/06/07/a/assets/grid_barcode_3.webp "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.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Windows Forms Tutorial: Create Your First Windows Forms C# Application](https://www.textcontrol.com/blog/2024/08/26/windows-forms-tutorial-create-your-first-windows-forms-csharp-application/llms.txt)
- [How to Mail Merge MS Word DOCX Documents in ASP.NET Core C#](https://www.textcontrol.com/blog/2023/10/16/how-to-mail-merge-ms-word-docx-documents-in-aspnet-core-csharp/llms.txt)
- [Creating an Angular Document Editor Application with a Node.js WebSocket Server](https://www.textcontrol.com/blog/2023/08/24/creating-an-angular-document-editor-application-with-a-nodejs-websocket-server/llms.txt)
- [Adding SVG Watermarks to Documents](https://www.textcontrol.com/blog/2022/01/28/adding-svg-watermarks-to-documents/llms.txt)
- [Using MailMerge in ASP.NET Core 6 Web Applications](https://www.textcontrol.com/blog/2022/01/27/using-mailmerge-in-aspnet-core-6-web-applications/llms.txt)
- [DocumentViewer for React Prerelease](https://www.textcontrol.com/blog/2020/10/27/document-viewer-for-react-prerelease/llms.txt)
- [New DocumentViewer Signature Tutorial Sample](https://www.textcontrol.com/blog/2020/08/18/new-documentviewer-signature-tutorial-sample/llms.txt)
- [Creating an ASP.NET MVC DocumentViewer Application With Razor](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-mvc-documentviewer-application-with-razor/llms.txt)
- [Creating Your First Windows Forms Application with C#](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-windows-forms-application-with-csharp/llms.txt)
- [Creating Your First WPF Application](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-wpf-application/llms.txt)
- [Creating a WPF Ribbon Application](https://www.textcontrol.com/blog/2020/01/01/creating-a-wpf-ribbon-application/llms.txt)
- [Integrate Document Editing into any HTML Client using the HTML Widget](https://www.textcontrol.com/blog/2020/01/01/integrate-document-editing/llms.txt)
- [Creating an ASP.NET MVC Application With Razor](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-mvc-application-with-razor/llms.txt)
- [Creating A Windows Forms Ribbon Application](https://www.textcontrol.com/blog/2020/01/01/creating-a-windows-forms-ribbon-application/llms.txt)
- [Creating Your First ASP.NET Reporting Application](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-aspnet-reporting-application/llms.txt)
- [Creating an ASP.NET Web Forms AJAX Application](https://www.textcontrol.com/blog/2020/01/01/creating-an-aspnet-web-forms-ajax-application/llms.txt)
- [Creating a WebSocket Server Project with Node.js](https://www.textcontrol.com/blog/2020/01/01/creating-a-websocket-server-project-with-nodejs/llms.txt)
- [Creating an Angular Document Editor Application](https://www.textcontrol.com/blog/2020/01/01/creating-an-angular-document-editor-application/llms.txt)
- [ReportingCloud .NET Core Quickstart Tutorial](https://www.textcontrol.com/blog/2019/07/24/reportingcloud-dotnet-core-quickstart-tutorial/llms.txt)
- [Document Permissions and Password Encryption](https://www.textcontrol.com/blog/2019/07/05/document-permissions-and-password-encryption/llms.txt)
- [New Online Sample: Build your First Report](https://www.textcontrol.com/blog/2019/07/03/build-your-first-report/llms.txt)
- [Create your First Document with ReportingCloud](https://www.textcontrol.com/blog/2019/02/19/create-your-first-document-with-reportingcloud/llms.txt)
- [MailMerge: Starting Each Merge Block on a New Page](https://www.textcontrol.com/blog/2016/09/09/mailmerge-starting-each-merge-block-on-a-new-page/llms.txt)
- [Windows Forms and WPF: End a List on Return when Line is Empty](https://www.textcontrol.com/blog/2016/08/26/windows-forms-and-wpf-end-a-list-on-return-when-line-is-empty/llms.txt)
- [Using IFormattedText Objects to Access Elements Across All TextParts in a Document](https://www.textcontrol.com/blog/2016/08/25/using-iformattedtext-objects-to-access-elements-across-all-textparts-in-a-document/llms.txt)
