我有一个gridview,它有很多数据(来自数据库)。我想把它的打印出来。以下代码工作正常,如果我只有1页打印(我的意思是只有44行记录)。如果没有打印出gridview内容的其余部分。
如果我要在多个页面上打印数据,允许多页打印需要进行哪些更改?
任何人都请帮助我......提前衷心感谢...我的代码附在下面......期待快速而明确的回答......
Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim ColumnCount As Integer = DataGridView1.ColumnCount
Dim RowCount As Integer = DataGridView1.RowCount
Dim CellTopPos As Integer = 1
For Row = 0 To RowCount - 1
Dim CellLeftPos As Integer = PrintDocument1.PrinterSettings.DefaultPageSettings.Margins.Left
For Cell = 0 To ColumnCount - 1
Dim CellValue As String = DataGridView1.Rows(Row).Cells(Cell).Value.ToString()
Dim CellWidth = DataGridView1.Rows(Row).Cells(Cell).Size.Width + 50
Dim CellHeight = DataGridView1.Rows(Row).Cells(Cell).Size.Height
Dim Brush As New SolidBrush(Color.Black)
e.Graphics.DrawString(CellValue, New Font("Century Gothic", 10), Brush, CellLeftPos, CellTopPos)
e.Graphics.DrawRectangle(Pens.Black, CellLeftPos, CellTopPos, CellWidth, CellHeight)
CellLeftPos += CellWidth
Next
CellTopPos += DataGridView1.Rows(Row).Cells(0).Size.Height
Next
End sub
Private Sub Button1_Click_1(sender As System.Object, e As System.EventArgs) Handles Button1.Click
preview.PrintDialog1.Document = PrintDocument1
preview.PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings
preview.PrintPreviewControl1.Document = PrintDocument1()
PrintDocument1.PrinterSettings.DefaultPageSettings.Landscape = False
preview.ShowDialog()
AddHandler PrintDocument1.PrintPage, AddressOf PrintDocument1_PrintPage
End Sub