473,327 Members | 2,025 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,327 software developers and data experts.

Print a long datagridview

3
HI,
I WORK WITH PRINTDOCUMENT CONTROL AND I WANT TO PRINT MORE THAN 1 PAGES. I PUT IN PrintDocument1_PrintPage CODE :

Expand|Select|Wrap|Line Numbers
  1.  Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
  2.  
  3.         Dim Lm As Integer
  4.         Dim Rm, dgvRows As Integer
  5.         Dim HasMorePages As Boolean = True
  6.         Static pagenum As Integer
  7.         With Form9.dgv2
  8.             Dim fmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
  9.             fmt.LineAlignment = StringAlignment.Center
  10.             fmt.Trimming = StringTrimming.EllipsisCharacter
  11.             Dim y As Single = e.MarginBounds.Top  'ΕΧΕΙ ΤΙΜΗ 100
  12.             newPage = True
  13.             Do While mRow < Form9.dgv2.RowCount                 
  14.                 Dim row As DataGridViewRow = Form9.dgv2.Rows(mRow)
  15.                 Dim x As Single = e.MarginBounds.Left - 95
  16.                 Dim h As Single = 0
  17.  
  18.                 For Each cell As DataGridViewCell In row.Cells
  19.                     Dim rc As RectangleF = New RectangleF(x, y, cell.Size.Width, cell.Size.Height)
  20.                     e.Graphics.DrawRectangle(Pens.Black, rc.Left, rc.Top, rc.Width, rc.Height)
  21.                     If (newPage) Then
  22.                         PrintFont = New Font("arial black", 7)
  23.                         e.Graphics.DrawString(Form9.dgv2.Columns(cell.ColumnIndex).HeaderText, PrintFont, Brushes.Black, rc, fmt)
  24.                     Else                      e.Graphics.DrawString(Form9.dgv2.Rows(cell.RowIndex).Cells(cell.ColumnIndex).FormattedValue.ToString(), Form9.dgv2.Font, Brushes.Black, rc, fmt)
  25.                     End If
  26.                     x += rc.Width
  27.                     h = Math.Max(h, rc.Height)
  28.                 Next
  29.                 newPage = False
  30.                 y += h
  31.                 mRow += 1
  32.                 If y + h > e.MarginBounds.Bottom - 100 Then
  33.                     e.HasMorePages = HasMorePages
  34.                     mRow = mRow - 1                     
  35.                     Exit Sub
  36.                 End If
  37.             Loop
  38.             mRow = 0
  39.  
  40.         End With
  41.  
  42.     End Sub ]
  43.  
  44. IN CREATING PREVIEWS MESSAGEBOX SHOWS THAT CREATES 2 PAGES. IN THE PRINDOCUMET AREA IN THE SCREEN SHOWS THE 1 PAGE. IN PRINT BUTTON PUT THE CODE :
  45. [ Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
  46.         PrintPreviewDialog1.Document = PrintDocument1 
  47.         PrintPreviewDialog1.ShowDialog()  
  48.     End Sub 
BUT WHEN I PUSH PRINT BUTTON PRINTS ME ONLY THE SECOND PAGE.
CAN ANYONE HELP ME ?
THANKS
Jun 12 '14 #1
2 1485
There isn't any built in printing support, so there are two options:
1) Use the standard printing system provided by Windows Forms and manually print out the information that you want. Check out the documentation for PrintPage and PrintDocument

2) Use the DataGridView's clipboard copy support to copy the content to an Excel file and then print that.
Jun 13 '14 #2
GFVB
3
Jennypliskin,
Thanks a lot for your help.
Jun 13 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Arno Au | last post by:
Hi, how can I print the content of a datagridview in vb 2005? thanks for answers, Arno
3
by: Marc | last post by:
Hallo, can someone tell me, how i could print a datagridview? I found in the whole net nothing :( bye
67
by: lcw1964 | last post by:
This may be in the category of bush-league rudimentary, but I am quite perplexed on this and diligent Googling has not provided me with a clear straight answer--perhaps I don't know how to ask the...
3
by: Daniel Manes | last post by:
I need a strategy to debug this situation... I can't put all the code involved, but here are some of the critical lines with comments: ------------------------- Private _parentDataCell As...
1
by: vanderlej | last post by:
does anyone have code for PrintPreview and print of DataGridView? thanks
0
by: murali007 | last post by:
Hi, i have to print datagridview content and some text using c# in windows application.. iam able to print datagridview print seperate and text seperate print .. but iam not able to print both...
1
by: gleave | last post by:
Hi, below is the code i got to print a datagridview, the trouble is it also prints visible columns which i don't want to be printed. Does anyone have any ideas on how i could change the code so it...
1
by: remya1000 | last post by:
I’m using VB.Net 2008 application program. I’m using DataGridView. I have a Print option where i need to print the DataGridView. I’m using this code for Printing and for Print Preview. ...
0
by: remya1000 | last post by:
I’m using VB.Net 2008 application program. I’m using DataGridView. I have a Print Preview option where i need to print the DataGridView. I’m using this code for Print Preview. Dim...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.