How to DataGridView Printing
The DataGridView control offers an exceptional platform for presenting data in a customizable and visually appealing table format. It equips developers with an extensive range of properties, methods, and events that empower them to fine-tune every aspect of the control's appearance and behavior.
However, it is worth noting that the DataGridView control does not provide an inherent printing functionality, which could be seen as a limitation. Nevertheless, ingenious workarounds exist to overcome this limitation and achieve the desired printing capability.
One such approach involves incorporating a PrintDocument object into the project and utilizing the power of the PrintPage event. This event is triggered whenever a new page is ready to be printed, providing an opportune moment to execute the necessary printing operations.
Within the PrintPage event handler, a Bitmap object is ingeniously created, serving as a canvas for rendering the DataGridView's contents. This Bitmap object acts as an intermediary, facilitating the transformation of the DataGridView into a printable format. By skillfully drawing the DataGridView onto this Bitmap object, the desired content is precisely captured and prepared for printing.
Full Source VB.NETIn order to run this vb.net project you have to drag two buttons ,one for load data and one for print command, and drag a PrintDocument control on your form . The following picture shows how to drag PrintDocument Object to your project.
- VB.NET DataGridView binding - Sql Server
- DataGridView binding - OLEDB in VB.NET
- DataGridView Sorting/Filtering in VB.NET
- DataGridView adding rows and columns in VB.NET
- DataGridView hiding rows and columns in VB.NET
- DataGridView ReadOnly rows and columns in VB.NET
- Adding Button to DataGridView in VB.NET
- Adding CheckBox to DataGridView in VB.NET
- Adding ComboBox to DataGridView in VB.NET
- Adding Image to DataGridView in VB.NET
- Adding ViewLink to DataGridView in VB.NET
- How to Paging in DataGridView
- How to Formatting in DataGridView
- How to DataGridView Template
- How to Export datagridview to Excel
- How to Import data from Excel to DataGridView
- Database operations in DatagridView
- Delete row from datagridview by Right click
- DataGridView Autocomplete TextBox in VB.Net