Results 1 to 2 of 2

Thread: [VB.NET] Print selected datagridview row into individual pages with front and back

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2015
    Location
    Bukit Mertajam
    Posts
    5

    [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
    Attached Images Attached Images  

  2. #2
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: [VB.NET] Print selected datagridview row into individual pages with front and bac

    Would a report not work out for this?

    I vision a page break per employee and the option to print duplex is a printer option.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width