Hi OriginalGriff,
Thank you for your response....
Here is the code I am using at the moment so you can see yourself if I am "doing the job properly".
This part is the "click event"......
Private Sub DomainsToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles DomainsToolStripMenuItem.Click
Me.PrintPreviewDialog1.Document = New System.Drawing.Printing.PrintDocument
PrintDocument2.DefaultPageSettings.Landscape = True
AddHandler PrintPreviewDialog1.Document.PrintPage, _
AddressOf PrintDocument2_PrintPage
pageNumber = 1
Me.PrintPreviewDialog1.ShowDialog()
End Sub
Here is the Print Document.....
Private Sub PrintDocument2_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument2.PrintPage
PrintDocument2.DefaultPageSettings.Landscape = True
Static mRow As Integer = 0
Dim fmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
Dim hfmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
Dim tfmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
Dim drwfont As New Font("Arial", 7.5)
Dim drawfont As New Font("Arial", 11, FontStyle.Bold)
fmt.Alignment = StringAlignment.Center
hfmt.Alignment = StringAlignment.Center
fmt.LineAlignment = StringAlignment.Center
hfmt.LineAlignment = StringAlignment.Center
fmt.Trimming = StringTrimming.EllipsisCharacter
tfmt.Alignment = StringAlignment.Center
tfmt.LineAlignment = StringAlignment.Center
'Print the page number.
e.Graphics.DrawString(Me.pageNumber, New Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, 400, 1050, tfmt)
If pageNumber = 1 Then
Dim MyString As String = "Document Title"
e.Graphics.DrawString(MyString, New Font("Arial", 16, FontStyle.Bold), Brushes.Black, 230, 60)
End If
Dim y0 As Single = 150
Dim y As Single = y0
With DataGridView1
While mRow < .RowCount
Dim row As DataGridViewRow = .Rows(mRow)
Dim x As Single = 20
Dim h As Single = 0
For Each cell As DataGridViewCell In row.Cells
Dim rc As RectangleF = New RectangleF(x, y, cell.Size.Width + 2, cell.Size.Height)
e.Graphics.DrawRectangle(Pens.Black, rc.Left, rc.Top, rc.Width, rc.Height)
If (y = y0) Then
e.Graphics.DrawString(DataGridView1.Columns(cell.ColumnIndex).HeaderText, drawfont, Brushes.Black, rc, hfmt)
Else
e.Graphics.DrawString(DataGridView1.Rows(cell.RowIndex).Cells(cell.ColumnIndex).FormattedValue.ToString(), drwfont, Brushes.Black, rc, fmt)
End If
x += rc.Width
h = Math.Max(h, rc.Height)
Next
y += h
mRow += 1
If (y + h) > e.MarginBounds.Bottom Then Exit While
End While
If mRow < .RowCount Then e.HasMorePages = True Else mRow = 0
pageNumber += 1
End With
End Sub
Not really sure how this might compare to the link you provided.
At the moment the code works perfectly fine for a larger table with a lot more columns but as I stated in my original question, as a particular grid is fairly narrow, I would prefer it if the table was split across a single page into 2 or 3 tables and then move to a new page rather than one long table over 2 or 3 pages.
I hope all this makes sense!!!?/
Cheers,
Aaron