Important alert: (current site time 7/15/2013 8:02:03 AM EDT)
 

winzip icon

DataGridViewPrinter Class

Email
Submitted on: 5/20/2006 9:29:07 AM
By: Salan S. Al-Ani 
Level: Intermediate
User Rating: By 6 Users
Compatibility: C#
Views: 23866
author picture
(About the author)
 
     Please refer to the following url for more details on how to use the class: http://www.codeproject.com/csharp/datagridviewprinter.asp The Class Features: (1) The print style is almost the same as the style of the DataGridView control: (A) the same font style for the header and other rows, (B) the same foreground and background styles for the header and other rows, (C) the same alternating background style for the rows, (D) special font for certain rows will be considered, (E) special foreground and background styles for certain rows will be considered, (F) the same alignment for the columns. (2) Supports multiple pages. (3) The width of each column to be printed is calculated to fit all the cells (including the header cell). (4) The title at the top of the page can be specified. (5) The title font and color could be specified. (6) The title and the header row are repeated in each page. (7) The report could be top-centered (considering the top margin of the page) on the page or be aligned to the top-left margin. (8) The printing process ignores any invisible rows or columns (assuming that the user does not want them to appear). (9) If the DataGridView width is greater than the page width, then the columns with x coordinate greater than the page width will be printed into another page. This ensures that all columns will be printed (Thanks to Stephen Long). (10) Support page numbering. (11) The printing process uses Graphics.MeasureString to calculate the height and width for a certain text with a specified font. This ensures the preciseness of the printing. (12) The class supports Right-to-Left fonts.

 
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 including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


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
5/19/2006 6:59:13 PMPoonam

Hi,
Your code is excellent and easy to use.I am trying to implement it
in one of my college project.

The problem is that I am able to print dataGridView but for some
reason RowHeader is not printing. rowHeader is missing in Printout.

Can you please tell me any way to print rowHeader too.

Thanks in advance.
Poonam.
(If this comment was disrespectful, please report it.)

 
5/20/2006 9:40:39 AMSalan S. Al-Ani

This was a bug in the class, and I fixed it. Please, download the updated version of the class/project which has many fixes and additional features.

You could obtain the update from same url in the planet-source-code.com:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txt CodeId=4638&lngWId=10

Or
refer to the below url for more details showing the class features and how to use it:
http://www.codeproject.com/csharp/datagridviewprinter.asp

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

 
9/8/2006 4:39:57 PMMark Wesbeek

Thank you, exactly what I was looking for!
(If this comment was disrespectful, please report it.)

 
9/9/2006 3:54:30 AMNavdeep

hello Sir,
Its really very nice code.
is it possible in vb.net if yes then plz help or give me some tips to do.

Thanks & regards
Navdeep Singh

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

 
9/9/2006 5:00:18 AMSalan S. Al-Ani

Please refer to the below link about this class for more details:
http://www.codeproject.com/csharp/datagridviewprinter.asp

You will find also on the feedbacks some guys that ported this class to VB.NET and you could ask them to have a copy of this.
(If this comment was disrespectful, please report it.)

 
11/18/2006 3:28:06 AMMuhammad Waqas Butt

Hi nice artical. But I'm not sure that your artical has the wraptext function not.I'm mean something like this if a column text is bigger than the width of column then if shift the text in the next line. Hope i make my point clear to you, anyways nice job if thought if this function adds in it that will greate. hope you will do something for it.

Thanks and best regards,

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

 
8/18/2008 6:46:29 AMdharani

hello sir ..
iam fresher in field ..please help me how to open this zip file..
(If this comment was disrespectful, please report it.)

 
2/2/2012 1:44:12 PMSavs

hello Sir,
Its really very nice code.
is it possible in vb.net if yes then plz help or give me some tips to do.

Thanks & regards
Navdeep Singh

here is vb.net code

http://vb.net-informations.com/datagridview/vb.net_datagridview_printing.htm

savs.


(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.