r/dotnet•
genuineSwag

[Visual Basic .NET - 2010 - FrameWork 4]Need help with printing multiple pages

I was asked to make program, which: After you select few rows in datagridview it checks if 1 or more was selected. If one, print two copies of report on one page(One report = half page) If more: Print two reports per page, printing as much as needed pages. Problem is, my code prints 4531456453 pages of same report(first and second row) :/

Basic example of code:

yPos = 0
Do While tmpI < mydatagridview.SelectedRows.Count - 1
    For Each selectedrow As DataGridViewRow In mydatagridview.SelectedRows
        Dim data as string = mydatagridview.SelectedRows(selectedrow.index).cells(1).value
        Dim data2 as string = mydatagridview.SelectedRows(selectedrow.index).cells(12).value

        e.graphics.drawstring(data, drawfont, (e.graphics.pagebound.width/2-e.graphics.measurestring(data, drawfont).width/2), 25+yPos)
        e.graphics.drawstring(data2, drawfont, (e.graphics.pagebound.width/2-e.graphics.measurestring(data2, drawfont).width/2), 50+yPos)
        yPos += e.pagebounds.height/2
        tmpI += 1 
        If yPos > e.pagebound.height/2 Then
            h = 0
            e.HasMorePages = true
            Exit Sub
        End If
    Next selecedrow
Loop

As of right now, as I said before it prints infinite amount of pages having data and data2 from SelectedRows with indexes 0 and 1.

Posted Jun 5, 2013, 3:56 PM UTC

10

No comments yet

Nobody commented on this post, or the comments weren't captured.