[VB.NET] Print selected datagridview row into individual pages with front and back
Hi,now I'm trying to print a datagridview cell data (NOT the whole datagridview) into individual page (ID card badge actually),according to individual rows,the new requirement here is certain data is print at FRONT,while certain data is print at BACK.
Google gave me some examples which work ONLY at one print event only.Mean each time only one FRONT and BACK of card are printed,then have to re run the whole process again.
For my understanding,it's related to Duplex printing and need to workaround the PageNumber and also HasMorePages,but I have no clue where to insert the related codes.
Here is my sample codes,which work well on FRONT pages printing:
Private rowsToPrint As Queue(Of DataGridViewRow)
Private Sub PrintDocument1_BeginPrint(sender As Object, e As PrintEventArgs) Handles PrintDocument1.BeginPrint
Dim sr = DataGridView1.SelectedRows
If sr.Count = 0 Then
e.Cancel = True
Else
rowsToPrint = New Queue(Of DataGridViewRow)(sr.Cast(Of DataGridViewRow)())
End If
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim rtp = rowsToPrint.Dequeue()
Dim s2 As String = rtp.Cells(2).Value.ToString
Dim f2 As New Font("Arial", 10)
Dim s4 As String = rtp.Cells(4).Value.ToString
Dim f4 As New Font("Arial", 10)
e.Graphics.DrawString(s2, f2, Brushes.Black, 10, 10)
e.Graphics.DrawString(s4, f4, Brushes.Black, 30, 30)
e.HasMorePages = rowsToPrint.Any()
End Sub