Results 1 to 2 of 2

Thread: Printing multiple pages with listview

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    1

    Post Printing multiple pages with listview

    When trying to print it only prints the first page. What wrong

    Dim fntPrintFont As New Font("Arial", 10)
    Dim fntHeadingFont As New Font("Arial", 14, FontStyle.Bold)
    Dim fntColumnHeading As New Font("Arial", 12, FontStyle.Bold)
    Dim sngLineHeight As Single = fntPrintFont.GetHeight + 2
    Dim sngXCol1 As Single = e.MarginBounds.Left
    Dim sngXCol2 As Single = 250.0F
    Dim sngXCol3 As Single = 350.0F
    Dim sngXCol4 As Single = 450.0F
    Dim sngXCol5 As Single = 550.0F
    Dim sngY As Single = e.MarginBounds.Top
    Dim strPrintline As String
    Dim intListCount As Integer = 0

    strPrintline = mMachineNo
    e.Graphics.DrawString(strPrintline, fntHeadingFont, Brushes.Black, sngXCol1, sngY)
    sngY += sngLineHeight * 2
    strPrintline = "Date"
    e.Graphics.DrawString(strPrintline, fntColumnHeading, Brushes.Black, sngXCol1, sngY)
    strPrintline = "stand1"
    e.Graphics.DrawString(strPrintline, fntColumnHeading, Brushes.Black, sngXCol2, sngY)
    strPrintline = "stand2"
    e.Graphics.DrawString(strPrintline, fntColumnHeading, Brushes.Black, sngXCol3, sngY)
    strPrintline = "Day"
    e.Graphics.DrawString(strPrintline, fntColumnHeading, Brushes.Black, sngXCol4, sngY)
    strPrintline = "Notes"
    e.Graphics.DrawString(strPrintline, fntColumnHeading, Brushes.Black, sngXCol5, sngY)
    sngY += sngLineHeight
    sngY += sngLineHeight
    For intListCount = 0 To lvPayments.Items.Count - 1
    e.Graphics.DrawString(lvPayments.Items(intListCount).Text, fntPrintFont, Brushes.Black, sngXCol1, sngY)
    e.Graphics.DrawString(lvPayments.Items(intListCount).SubItems(1).Text, fntPrintFont, Brushes.Black, sngXCol2, sngY)
    e.Graphics.DrawString(lvPayments.Items(intListCount).SubItems(2).Text, fntPrintFont, Brushes.Black, sngXCol3, sngY)
    e.Graphics.DrawString(lvPayments.Items(intListCount).SubItems(3).Text, fntPrintFont, Brushes.Black, sngXCol4, sngY)
    e.Graphics.DrawString(lvPayments.Items(intListCount).SubItems(4).Text, fntPrintFont, Brushes.Black, sngXCol5, sngY)
    sngY += sngLineHeight
    Next

    If intListCount < lvPayments.Items.Count - 1 Then
    e.HasMorePages = True
    Else
    e.HasMorePages = False
    End If

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Printing multiple pages with listview

    Your loop says this:
    vb.net Code:
    1. For intListCount = 0 To lvPayments.Items.Count - 1
    and then your code does this:
    vb.net Code:
    1. If intListCount < lvPayments.Items.Count - 1 Then
    Unless you break out of that loop before it's finished, which you don't, how can that If condition ever be True? As such, e.HasMorePages is always going to be set to False, so no more pages get printed.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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