Errr..Print The Datagrid? ( and more )

Nerine

Member
Joined
Nov 24, 2005
Messages
13
Location
Nede..Expel...???
Programming Experience
1-3
How To Print The content of The Data grid? ( In theTable Format )
i know Somewhere have the code but it hard and the code is too long to understand so i need easy and short version of the code for more easy to understand how the print work...

Other is i also want to print the data in the form that just retrieve from database and how to make it print at form format ???


p/s : pls correct me if i post on wrong section and the thing that i write too confused...:(
 
If you search this forum for "print datagrid" you will find solutions
 
but most of the post show the same result...
the link to the same thing...
if can where can i find tutorial coz i need to understand it..??:confused:

p/s : sorry if i ask too much :eek:
 
It's the same thing as with all printing in .Net, you have to position and draw all text/value/image yourself.

Since it is some work to get the big dynamics of a datagrid to print nice, and it's not an uncommon task, there exist a few custom datagrids with printing or classes that will do it for you.

So you can get one of the controls or use the regular printing technique to print content.

If you search Google et.al. you will find lots of articles on "how to print in VB.Net"
 
As JohnH suggests, there is only one way to print in .NET. If you want to undersatnd the printing process then I strongly suggest that you don't start with a DataGrid, as it is a rather complex printing problem. If you really want to understand the printing process then start with the printing sample in the 101 samples from Microsoft and read about the printing-related classes, mainly the PrintDocument class. Once you have the basics then you can build up to something like a DataGrid. If you want to just print a DataGrid now then I'd suggest just using a ready-made class from someone else as you'll probably only confuse yourself. There are some third-party grids around that support printing, plus there are some helper classes around that allow you to print a standard DataGrid.

Here's a link to a helper class. By all means try to work out the code but it is complex. As with everything, if you want to master printing in .NET then you need to walk before you can run.
 
err... what version are you using then?
 
i read almost all the tutorial but all of it only show how to print the list box and not show how to print form that contain textbox, combobox, etc..

so anyone can show me a sample on print textbox with combobox , etc....
like formating for textboxbox etc...



p/s : sorry for always ask too much ^^
 
You print everything in .NET the same way. You call Print on a PrintDocument
and then you handle the PrintPage event. Within that event handler you draw WHATEVER you want. If you want to draw the Text from TextBox then you do so by passing it to a call to DrawString. That is the way you print any and all text. You need to adapt what you've seen to your specific situation. You can't expect there to be an example for every different set of circumstances. If you know how to get the Text from a TextBox and you know how to print a string then you know how to print the Text from a TextBox. It's up to you to put the two parts together.
 
The e.Graphics property in the PrintPage event handler is used to draw EVERYTHING. If you want to print a line you call DrawLine. If you want to print a string you call DrawString. If you want to print a rectangle you call DrawRectangle, an so on.

As for e.HasMorePages, if you set it to False then the printing process will stop after that page. If you set it to True then the PrintPage event will be raised again to print the next page. It's up to you to use static or class-level variables to keep track of where you are up to in the printing process so that the correct page is printed each time the PrintPage event is raised.
 
i don't what code should i put on here..
.................................................||
.................................................\/
e.graphics.drawrectangles( 'what code on here ' )
 
Back
Top