By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,995 Members | 1,073 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,995 IT Pros & Developers. It's quick & easy.

Printing all data in datagrid?

P: n/a
Hi all,
I need to print all the data in my datagrid to a printer, and the user
must be able to choose whether with the grid lines or without. I am a
beginner in .net and I would appreciate any help!!!
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
you will be using the drawing namespace when you are writing to the
printer .... so actually you will be drawing the lines and even the values
form the datagrid one by one.(this is the way to write to the printer,
using drawing)
what you can do it to ues a check box that set a boolean
variable"use would check it if he wants to draw lines". then check this
value inside the printpage handler, if it is set, then use the drawline
method of drawing between values , otherwise, you skip this step .....
hope that would help

Nov 15 '05 #2

P: n/a

Yea, thanks, that helps a lot. Do I have to go through the datagrid or
the dataset? And I looked at code samples for printing, and it doesn't
make any sense. They use a class derived from the printDocument class,
and X and Y positions. Is that the easiest way to go about it? It looks
quite complicated. Does anyone have a piece of code for the printing? It
looks like all the examples I have been looking at don't only do the

Thanks a lot!!!

*** Sent via Developersdex ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3

P: n/a
Look in the simplest form . you will be adding a PrintDocument object to
your class
private System.Drawing.Printing.PrintDocument printDocument1;
you might add a printdialog and set its printdocument properety to your
print document.

You might also need to add PageSettings and assign it to your printdocument.

PageSettings myPageSettings=new PageSettings();

the only thing that you have to do in order to print is to write a handler
to the printpage event of the printdocumnet object
private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)

e.Graphics.PageUnit=GraphicsUnit.Millimeter; //set the mode that you
will be using

//then to write values form the dataset or the datagrid this is your
To write just use
private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
e.Graphics.DrawString("these are the values that are inside my dataset");
//after you enter one complete row you can then draw a line before
//starting the new row
e.Graphics.DrawLine(new Pen(new SolidBrush(Color.Red)),0,0,100,100);

//then you check to see if you are done or not, if not set the has //more
pages to true so the print event would be fired again to print //more pages
If(//your test condition , the data in the dataset is done or not may be){
e.HasMorePages =true;
}else { e.HasMorePages =false;


hope that would help
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.