winzip icon

Print DataGridView

Submitted on: 1/6/2015 9:37:00 AM
By: Ignyte Software, Inc. (from psc cd)  
Level: Intermediate
User Rating: By 6 Users
Compatibility: VB.NET
Views: 15642
     This code shows how to print the data from a Visual Studio .Net DataGridView. It also includes the following features: - Page header - Column headers from DataGridView - Page footer - Handle multiple pages of data - Pass in a parameter for printing in portrait or landscape orientation - Option to display a print preview dialog

winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net

Other 4 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

8/13/2015 4:27:24 PMSuresh

Hi, it is Excellent
i have some doubt, i have already formatted data in DataGridView, But this removes all the formatted data and gives printing as it is
How to get Print all columns as same as in GridView ?
Please help
(If this comment was disrespectful, please report it.)

2/2/2016 7:35:04 AMSameer

Dear, First of all thank you very much for sharing this great piece of code.
But it is skipping last record during print preview whether the number of pages are 1 or more. can you please let me know what update should be provided to this code ?

Thank you.
(If this comment was disrespectful, please report it.)

7/23/2016 4:29:11 AMmikado

thank you very much ...
(If this comment was disrespectful, please report it.)

9/27/2017 2:46:53 PMchuckie

This doesn't like to have an oCell without a value. I don't mean a string that is null but rather a Double, for example, that is Nothing. So test the cell for a value and put that (or " ") in cellStringValue then print that.

e.Graphics.DrawString(cellStringValue, oCell.InheritedStyle.Font, New SolidBrush(oCell.InheritedStyle.ForeColor), New RectangleF(oColumnLefts(i), nTop, oColumnWidths(i), nHeight), oStringFormat)

(If this comment was disrespectful, please report it.)

12/30/2019 10:07:19 PMmzm

It prints from left to right,
how I can make it prints from right to left.
please help
(If this comment was disrespectful, please report it.)


Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.