I am new to vb.net windows form
I have code (bit map method) using which i can print data grid but only one page not if grid has multiple pages(many rows)
i want to print all the rows around 90 +
Please help me with code to print dgv
Code i am using now is below -
Private Sub btnprint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprint.Click
-
PrintPreviewDialog1.Document = PrintDocument1
-
PrintPreviewDialog1.PrintPreviewControl.Zoom = 1
-
PrintPreviewDialog1.ShowDialog()
-
End Sub
-
-
-
Private Sub PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
-
Dim bm As New Bitmap(Me.DataGridView1.Width, Me.DataGridView1.Height)
-
DataGridView1.DrawToBitmap(bm, New Rectangle(0, 0, Me.DataGridView1.Width, Me.DataGridView1.Height))
-
e.Graphics.DrawImage(bm, 0, 0)
-
End Sub
-
1 1368
i found it by googling around if some one gets stucked hole my answer helps,do following
•First add Print Document1 and Print Preview Dialog1 to form on which data grid is placed from tool box.
•Then select print document1, go to properties and go to print page event
•In print page event write following code. -
-
With DataGridView1
-
Dim fmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
-
fmt.LineAlignment = StringAlignment.Center
-
fmt.Trimming = StringTrimming.EllipsisCharacter
-
Dim y As Single = e.MarginBounds.Top
-
Do While mRow < .RowCount
-
Dim row As DataGridViewRow = .Rows(mRow)
-
Dim x As Single = e.MarginBounds.Left
-
Dim h As Single = 0
-
For Each cell As DataGridViewCell In row.Cells
-
Dim rc As RectangleF = New RectangleF(x, y, cell.Size.Width, cell.Size.Height)
-
e.Graphics.DrawRectangle(Pens.Black, rc.Left, rc.Top, rc.Width, rc.Height)
-
If (newpage) Then
-
e.Graphics.DrawString(DataGridView1.Columns(cell.ColumnIndex).HeaderText, .Font, Brushes.Black, rc, fmt)
-
Else
-
e.Graphics.DrawString(DataGridView1.Rows(cell.RowIndex).Cells(cell.ColumnIndex).FormattedValue.ToString(), .Font, Brushes.Black, rc, fmt)
-
End If
-
x += rc.Width
-
h = Math.Max(h, rc.Height)
-
Next
-
newpage = False
-
y += h
-
mRow += 1
-
If y + h > e.MarginBounds.Bottom Then
-
e.HasMorePages = True
-
mRow -= 1
-
newpage = True
-
Exit Sub
-
End If
-
Loop
-
mRow = 0
-
End With
-
-
-
•On Click of print button write following code. -
-
PrintPreviewDialog1.Document = print
-
PrintPreviewDialog1.PrintPreviewControl.Zoom = 1
-
PrintPreviewDialog1.ShowDialog()
-
-
-
Bye hope it helps
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Wladimir Borsov |
last post by:
I would like to load multiple web pages from Internet into ONE single browser
window - one below the other. How do I do that most easily ?
One idea is to built a frameset (for e.g 6 web pages)...
|
by: mike |
last post by:
Hello all,
any advice or links to pages about how to have multiple language asp
pages? For example, you have a database driven website that you want
customers around the world to use. How do...
|
by: EagleRed |
last post by:
I am writing an ASP.NET 2.0 application that uses more than one master page.
Currently, there are two pages, Freedom1.master and Freedom2.master. I have
no problems with Freedom1.master. However,...
|
by: Bart Van der Donck |
last post by:
Hello,
I'm having a hard time trying to configure printed output that consists
of multiple pages. The idea is the following:
<div style="
border: 1px solid blue;
position: absolute;
top:...
|
by: LukeSkywacko |
last post by:
Hi, I would like to know how I could accomplish this without using DB.
There's a long text file named "TEST.TXT"
The TEST file contains special character 'º' which will be used as
pagebreak.
I...
| |
by: Murty |
last post by:
I am giving printout from windows xp. its give error message like "PRINTER CAN NOT PRINT SPOOLED REQUEST. SPOOLED PAGES ARE NOT PRINT
"
|
by: dan |
last post by:
I have 5 aspx pages that I'd like to share the same code behind file. Those
pages have the same set of 'core' controls and object data sources. Is this
a good practice? It seems that VS2005...
|
by: raul15791 |
last post by:
Hi,
I'm newbie in ASP. I am trying to view multiple pages by using a single file.
For example,
I have a few pages of product.asp (products.asp, products1.asp and so on). Now I want to create a...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |