I have the following code which prints my datagrid nicely. The problem is that it only prints the first page and cuts off everything thereafter. I know I need to implement the e.HasMorePages = True in some manner but I am unable to get that working.
Here is my code:
Dim x As Integer = 100
Dim y As Integer = 50
'draw headers
Dim j As Integer = 1
Do While (j < Me.FrameToOrderDataGridView.Columns.Count)
Dim rect As Rectangle = New Rectangle(x, y, Me.FrameToOrderDataGridView.Columns(j).Width, Me.FrameToOrderDataGridView.ColumnHeadersHeight)
Dim sf As StringFormat = New StringFormat
sf.LineAlignment = StringAlignment.Center
sf.Alignment = StringAlignment.Center
e.Graphics.FillRectangle(Brushes.LightGray, rect)
e.Graphics.DrawRectangle(Pens.Black, rect)
If (Not (Me.FrameToOrderDataGridView.Columns(j).HeaderText) Is Nothing) Then
e.Graphics.DrawString(Me.FrameToOrderDataGridView.Columns(j).HeaderText, SystemFonts.DefaultFont, Brushes.Black, rect, sf)
End If
x = (x + rect.Width)
j = (j + 1)
Loop
x = 100
y = (y + Me.FrameToOrderDataGridView.ColumnHeadersHeight)
'draw rows
For Each row As DataGridViewRow In Me.FrameToOrderDataGridView.Rows
Dim k As Integer = 1
Do While (k < Me.FrameToOrderDataGridView.Columns.Count)
Dim cell As DataGridViewCell
cell = row.Cells(k)
Dim rect As Rectangle = New Rectangle(x, y, cell.Size.Width, cell.Size.Height)
Dim sf As StringFormat = New StringFormat
sf.LineAlignment = StringAlignment.Center
sf.Alignment = StringAlignment.Center
e.Graphics.DrawRectangle(Pens.Black, rect)
If (Not (cell.Value) Is Nothing) Then
e.Graphics.DrawString(cell.EditedFormattedValue.ToString, SystemFonts.DefaultFont, Brushes.Black, rect, sf)
End If
x = (x + rect.Width)
k = (k + 1)
Loop
x = 100
y = (y + row.Height)
Next