How can I print and printpreview a datagrid?

Y

youngster94

I'm trying to print directly from a datagrid and I'm running into some
problems. Heres a snipit of code I'm using for printing:

'********************************************************************
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles btnPrint.Click
PrintDocument1.Print()
End Sub
'********************************************************************
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
PrintDocument1.PrintPage
Dim myPaintArgs As New PaintEventArgs(e.Graphics, New Rectangle(New
_
Point(0, 0), myDataGrid.Size))

Me.InvokePaint(myDataGrid, myPaintArgs)
End Sub
'********************************************************************


This only prints the visible part of the grid and not all the data in
the table. The reason I'm printing directly from the Datagrid is
because some of my cells are wordwrapped - wordwrap works when I print
from datagrid because what you see is what you get.

Any ideas how to print the whole datagrid(with unseen rows), as well as
the column headers on every carry over page?

Thanks a lot.

Josh
 
K

Ken Tucker [MVP]

Hi,

http://www.codeproject.com/vb/net/datagridex.asp

Ken
----------------
I'm trying to print directly from a datagrid and I'm running into some
problems. Heres a snipit of code I'm using for printing:

'********************************************************************
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles btnPrint.Click
PrintDocument1.Print()
End Sub
'********************************************************************
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
PrintDocument1.PrintPage
Dim myPaintArgs As New PaintEventArgs(e.Graphics, New Rectangle(New
_
Point(0, 0), myDataGrid.Size))

Me.InvokePaint(myDataGrid, myPaintArgs)
End Sub
'********************************************************************


This only prints the visible part of the grid and not all the data in
the table. The reason I'm printing directly from the Datagrid is
because some of my cells are wordwrapped - wordwrap works when I print
from datagrid because what you see is what you get.

Any ideas how to print the whole datagrid(with unseen rows), as well as
the column headers on every carry over page?

Thanks a lot.

Josh
 
J

Jack Russell

Ken said:
Hi,

http://www.codeproject.com/vb/net/datagridex.asp

Ken
----------------
I'm trying to print directly from a datagrid and I'm running into some
problems. Heres a snipit of code I'm using for printing:

'********************************************************************
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles btnPrint.Click
PrintDocument1.Print()
End Sub
'********************************************************************
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
PrintDocument1.PrintPage
Dim myPaintArgs As New PaintEventArgs(e.Graphics, New Rectangle(New
_
Point(0, 0), myDataGrid.Size))

Me.InvokePaint(myDataGrid, myPaintArgs)
End Sub
'********************************************************************


This only prints the visible part of the grid and not all the data in
the table. The reason I'm printing directly from the Datagrid is
because some of my cells are wordwrapped - wordwrap works when I print
from datagrid because what you see is what you get.

Any ideas how to print the whole datagrid(with unseen rows), as well as
the column headers on every carry over page?

Thanks a lot.

Josh
Spend the money on farpoints spread. No connection except as a happy
customer (and you can get real support).
 
Y

youngster94

Ken,
Thanks for the info. I've checked out the codeproject but have been
unsuccessful with getting the wordwrap to work. Even if I create code
to put in character returns the wrap will not work unless I manually
expand the rows one at a time - but even after that it will not print
the expanded row because it appears to print directly from the
datatable. If you know a way around this I think this solution will
work great.

Thanks,

Josh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top