Click here to Skip to main content
14,298,693 members
Rate this:
Please Sign up or sign in to vote.
See more:
I need to print somthing from datagrid to first page and same data but with more filds to another page ( price eg visible only on second page ).

Another problem is how to solve when I print laine from datagrid and there are more line then one page how to go next page.


What I have tried:

Private Sub printDocument2_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
             If ComboBox1.SelectedIndex = 1 Then
            a = 0
            Do While a < 2
                e.Graphics.DrawRectangle(p, 38, 400, 765, 30)
                e.HasMorePages = True
                a = a + 1

                e.Graphics.DrawRectangle(p, 38, 400, 765, 100)
            e.HasMorePages = False
        ElseIf ComboBox1.SelectedIndex = 0 Then
Updated 5-Sep-19 21:54pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

Keep a class level page number, and check that in your method.
Set HasMorePages to true unless you have just printed the last page, and increment the page count each time it's called. You may want to keep a "next line" variable as well to help you with the multipage DataGrid printing.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Using Return Statement[^] inside a Do While .. Loop loop causes return to the calling procedure.

It is quite easy to check:
Sub Main
End Sub

Sub DoSomething()
	Dim i As Integer = 0
	Do While i < 100
		Console.WriteLine("Current value of counter is: {0}", i)
End Sub

Current value of counter is: 0

Follow the link to get more details.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100