关于打印DataGridView被先中行的内容,不能正确产生分页,有代码,请高手指点~~
Private Sub print1(ByVal e As System.Drawing.Printing.PrintPageEventArgs, ByVal p As Integer)
Dim name1, city, company, sheng, shi, xian, qu, address, mobile, phone, postal As String
Dim adrstring As String = "Select * from addressee where ID=" & p & ""
Dim cmd As OleDbCommand = New OleDbCommand(adrstring, conn)
conn.Open()
Dim dataread As OleDbDataReader
dataread = cmd.ExecuteReader
While dataread.Read()
name1 = dataread("name").ToString
city = dataread("city").ToString
company = dataread("company").ToString
sheng = dataread("sheng").ToString
shi = dataread("shi").ToString
xian = dataread("xian").ToString
qu = dataread("qu").ToString
address = dataread("address").ToString
mobile = dataread("mobile").ToString
phone = dataread("phone").ToString
postal = dataread("postalcode").ToString
e.Graphics.PageUnit = GraphicsUnit.Millimeter
e.Graphics.DrawString(name1, New Font("宋体", 10.5, FontStyle.Regular), Brushes.Black, 130, 29)
e.Graphics.DrawString(city, New Font("宋体", 10.5, FontStyle.Regular), Brushes.Black, 165, 29)
e.Graphics.DrawString(company, New Font("宋体", 10.5, FontStyle.Regular), Brushes.Black, 135, 36)
e.Graphics.DrawString(sheng, New Font("宋体", 10.5, FontStyle.Regular), Brushes.Black, 124, 44)
e.Graphics.DrawString(shi, New Font("宋体", 10.5, FontStyle.Regular), Brushes.Black, 150, 44)
e.Graphics.DrawString(xian, New Font("宋体", 10.5, FontStyle.Regular), Brushes.Black, 169, 44)
e.Graphics.DrawString(qu, New Font("宋体", 10.5, FontStyle.Regular), Brushes.Black, 186, 44)
e.Graphics.DrawString(address, New Font("宋体", 10.5, FontStyle.Regular), Brushes.Black, New Drawing.RectangleF(112, 51, 94, 7))
e.Graphics.DrawString(mobile, New Font("宋体", 10.5, FontStyle.Regular), Brushes.Black, 141, 59)
e.Graphics.DrawString(phone, New Font("宋体", 10.5, FontStyle.Regular), Brushes.Black, 180, 59)
e.Graphics.DrawString(postal, New Font("宋体", 10.5, FontStyle.Regular), Brushes.Black, 120, 103)
End While
conn.Close()
End Sub
Dim num As Integer = 0
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
If Me.DataGridView1.Rows(num).Cells(1).EditedFormattedValue = True Then 'DataGridView中第一列是CheckBox列,当这列中有CheckBox被先中时执行下面
print1(e, Me.DataGridView1.Rows(num).Cells(0).Value) 'print1过程执行~~
num = num + 1
Else
num = num + 1
End If
If num < 5 Then '就这个地方不知道怎么弄,一执行Me.PrintPreviewDialog1.ShowDialog(),只能是出来5个预览页面,checkbox被选中的有内容,没有被选中的那页是空白。
e.HasMorePages = True
Else
e.HasMorePages = False
num = 0
End If
End Sub
执行上面代码,可以在PrintPreviewDialog中正常预览表中的数据,并能很好执行打印,现在问题想实现打印和预览的内容是datagridview中checkbox选被中的行。目前执和上面代码,不知道如何正确分页,使用这种传统分页方式,只能是全都预览出来,选中的有内容,没选中的就是个空白页。请高手指点下如何能正确的分页预览并打印,只打印选中的多行。选中行是在datagridview中随机选中的几行。 DataGridView 分页 打印 --------------------编程问答-------------------- 请老师们指点~~
--------------------编程问答-------------------- 怎么没人回,自己顶一下~~~ --------------------编程问答-------------------- 有没有什么方法麻烦回复一下 --------------------编程问答-------------------- 根据选中的,重新筛选一下,移除未选中的部分,再做可以么?
补充:.NET技术 , VB.NET