how to print data(VB.NET)

shohoku

Active member
Joined
Jun 15, 2005
Messages
31
Programming Experience
Beginner
[RESOLVED]how to print data(VB.NET)

i display my data in datagrid
and i wish to print it out
so i wrote down code below
[font=simsun,mssong,arial] StringToPrint = DataGrid1.Text
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
but when i run the program and click print preview
it come out nothing
how i gonna do for it?
how can i print the data in vb.net??
thanks!!!:confused:
[/font]
 
Last edited:
When printing in .net you have to handle all the details of printing yourself in the PrintPage event handler of the PrintDocument. You have to create the strings, lines, etc., you have to position them and then you have to draw them on the page. If you want to show a print preview, your code must run through the cycle of printing the pages twice: once for the preview and once for the actual print run. The good news for you is that someone has already created a derived DataGrid class that supports printing out of the box, without you having to do much of anything. I've never used it myself, but, as far as I know, it behaves just like a regular DataGrid in other respects. The advantage of this is that, once the necessary references have been added to your project, you simply do a find and replace in your code and change any mention of the DataGrid class name to the new name of the new class. Get this super, time-saving grid here.
 
That's good to hear. There are plenty of third party controls around like that. It's good to patrol various developer sites and see if there are useful things available.
 
Back
Top