Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 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.

Thanks

What I have tried:

VB
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)
                Return
            Loop
            e.HasMorePages = False
        ElseIf ComboBox1.SelectedIndex = 0 Then
Posted
Updated 5-Sep-19 21:54pm
v2

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

It is quite easy to check:
VB
Sub Main
	DoSomething()
End Sub

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


Result:
Current value of counter is: 0


Follow the link to get more details.
 
Share this answer
 
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900