所以我有打印文档显示来自我的datagridview的数据,我的问题是我想计算我的datagridview中的行,然后如果行超过10,它将切割数据1-10,然后在下一个显示剩余数据第 10-15 列以上。我一直坚持只显示数据,直到它到达页面的底部边缘,当它到达时,数据将转到下一页。
所以我想要这样看图片
但我只有这样的输出
计数 11 依此类推,直到到达底部边距,然后剩余的数据将转到下一页。
我怎样才能做到这一点?任何想法?
我的datagridview只有这个代码`
Dim mRow As Integer = 0
Dim newpage As Boolean = True
With dtgridvwPrint
Dim fmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
fmt.LineAlignment = StringAlignment.Center
fmt.Trimming = StringTrimming.EllipsisCharacter
Dim y As Single = e.PageBounds.Height - 700
Do While mRow < .RowCount
Dim row As DataGridViewRow = .Rows(mRow)
Dim x As Single = e.MarginBounds.Left
Dim h As Single = 0
Dim x1 As Single = e.PageBounds.Width - 500
Dim count As Integer
For Each rows As DataGridViewRow In dtgridvwPrint.Rows
count += dtgridvwPrint.RowCount
Next
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(dtgridvwPrint.Columns(cell.ColumnIndex).HeaderText, font1, Brushes.Black, rc, fmt)
Else
e.Graphics.DrawString(dtgridvwPrint.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 `