473,385 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How can I print and printpreview a datagrid?

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

Nov 21 '05 #1
3 3510
Hi,

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

Ken
----------------
<yo*********@hotmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
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
Nov 21 '05 #2
Ken Tucker [MVP] wrote:
Hi,

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

Ken
----------------
<yo*********@hotmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
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).
Nov 21 '05 #3
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

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: E. W via DotNetMonster.com | last post by:
Hi all, is it possible to configure a printpreview control so that I am able to print selected pages (for example 12-20 like by Word)? Thanks ew -- Message posted via DotNetMonster.com...
2
by: AG | last post by:
I am using PrintPreview control in my VB.NET application. But when we display print preview, only the last document is shown, and I cannot see five or six documents there. Seems like as soon...
1
by: cartist03 | last post by:
I am using printpreview dialog box control in my VB project. I can see the multipage document in preview but when I click on the Print icon in the dialog window, I get a blank page ! Does anyone...
1
by: ucasesoftware | last post by:
I have just a problem to margin the Datagrid... Could someone help me ? the datragid always print in the top LEFT #Region " Impression " 'Déclaration Private PrintPageSettings As New...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
0
by: Wilfredo Rivera | last post by:
Hello: In VB.net 2003. When running this application the document to be printed looks the way it's supposed to but when printed is not how it looked. For example; the program it's supposed to run...
3
by: Fareast Adam | last post by:
Here is the code; <head> <script> function printpreview() { var OLECMDID = 7; /* OLECMDID values: * 6 - print
7
by: Fareast Adam | last post by:
I try to hide the print preview button that inside <div id="button"> when previewing the page. But the the problem happened the button is always hidden after i closing the preview page. Anyone have...
5
by: maminx | last post by:
hello all, i want to call window print preview (in browser, File - Print Preview) by javascript, this is the code function printpreview() { var OLECMDID = 7; /* OLECMDID values: * 6...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.