I have the following code which handles my Print Button but I'm getting my ListView contents all on 1 page only (overwriting). How can I loop through the ListView items an d print on more than one page? Excuse my "newbiness".

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim prn As New Printing.PrintDocument
        AddHandler prn.PrintPage, AddressOf Me.PrintPageHandler
        RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHandler

End Sub

    Private Sub PrintPageHandler(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs)

        Dim lvwItem As ListViewItem
        Dim lvwSubItem As ListViewItem.ListViewSubItem
        Dim xPos As Integer = 0
        Dim yPos As Integer = 0

        ' Counter for display purposes
        Dim listviewcount As Integer = 1

        ' Loop through our listview items
        For Each lvwItem In ListViewPrograms.Items
            xPos = 0

            ' Print the count
            ' Debug.Print(listviewcount)

            ' Print the subitems of this particular ListViewItem
            For Each lvwSubItem In lvwItem.SubItems
                xPos += 100
                yPos = 100 + (listviewcount * 15)
                args.Graphics.DrawString(lvwSubItem.Text(), _
                    New Font("Arial", 8, FontStyle.Bold), Brushes.Black, xPos, yPos)

            ' Increment the count (for display purposes)
            listviewcount += 1

    End Sub

In your loop you must have to insert some code lines to choose for feeding new page or not.
To do this you will have to use args.HasMorePages = True / False

In DW here is a rich codesnippet library, from there you can read this snippet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.