|
-
Jan 4th, 2009, 12:55 PM
#1
Thread Starter
Member
Re: setting e.HasMorePages when Printing out a DataGridView using DataGridPrinter class
Andy, I tried putting some Debug.Write lines in the DataGridPrinter.vb file but nothing would show up on the output window. I dont know how to do break points
If it's any help, this is the code in the Print button on the form which displys the contents of the database
Code:
If GridPrinter Is Nothing Then
GridPrinter = New DataGridPrinter(Me.DataGridView1)
End If
'setting properties of dgview (after adding gridprinter )
With GridPrinter
.HeaderText = CStr("Report Dated - " & Today)
.HeaderHeightPercent = CInt(5)
.FooterHeightPercent = CInt(0)
.InterSectionSpacingPercent = CInt(3)
.PagesAcross = CInt(2)
End With
'printpreview prinout
With Me.PrintPreviewDialog1
.Document = GridPrinter.PrintDocument
If .ShowDialog = DialogResult.OK Then
GridPrinter.Print()
End If
End With
-
Jan 4th, 2009, 01:24 PM
#2
Re: setting e.HasMorePages when Printing out a DataGridView using DataGridPrinter cla
Put them just before the check that decides if .HasMorePages should be true or not.
Try this:
vb Code:
Debug.Writeline("_CurrPrintGridLine value : ", _CurrentPrintGridLine)
Debug.Writeline("GridRowCount value : ", GridRowCount())
If _CurrentPrintGridLine < GridRowCount() Then
e.HasMorePages = True
End If
Note that the 'Debug' lines will only execute if you build and run your app in Debug mode.
You could put Console.Writeline... instead, but then they will always execute, even if you compile the app in Release mode.
I would definitely recommend learning how to use a breakpoint. Very useful in debugging your app. It does what it says - 'breaks' execution allowing you to run your app step-by-step, inspect variable values, etc.
-
Jan 4th, 2009, 03:05 PM
#3
Thread Starter
Member
Re: setting e.HasMorePages when Printing out a DataGridView using DataGridPrinter class
I tried adding the code you said but I got the following 2 errors befoe I could even build it.
Code:
Error 1 Overload resolution failed because no accessible 'WriteLine' can be called without a narrowing conversion:
'Public Shared Sub WriteLine(value As Object, category As String)': Argument matching parameter 'category' narrows from 'Integer' to 'String'.
'Public Shared Sub WriteLine(message As String, category As String)': Argument matching parameter 'category' narrows from 'Integer' to 'String'. F:\Documents and Settings\Tommy\My Documents\Visual Studio 2005\Projects\FinalYearProject\FinalYearProject\DataGridPrinter.vb 475 9 FinalYearProject
Code:
Error 2 Overload resolution failed because no accessible 'WriteLine' can be called without a narrowing conversion:
'Public Shared Sub WriteLine(value As Object, category As String)': Argument matching parameter 'category' narrows from 'Integer' to 'String'.
'Public Shared Sub WriteLine(message As String, category As String)': Argument matching parameter 'category' narrows from 'Integer' to 'String'. F:\Documents and Settings\Tommy\My Documents\Visual Studio 2005\Projects\FinalYearProject\FinalYearProject\DataGridPrinter.vb 476 9 FinalYearProject
you also said I have to run it in debug mode, how would I do that?
-
Jan 4th, 2009, 03:42 PM
#4
Re: setting e.HasMorePages when Printing out a DataGridView using DataGridPrinter cla
Apologies, change the lines to this:
Code:
Debug.Writeline("_CurrPrintGridLine value : " & _CurrentPrintGridLine.ToString)
Debug.Writeline("GridRowCount value : " & GridRowCount.ToString)
You probably already are running in Debug mode.
Go to the Build menu, select Configuration manager and check that the Active Solution Configuration is set to Debug.
Or you can use the build configuration drop-down box on the toolstrip, depending on how your version of VB is set up.
-
Jan 4th, 2009, 04:17 PM
#5
Thread Starter
Member
Re: setting e.HasMorePages when Printing out a DataGridView using DataGridPrinter class
Worked like a charm! Output from debug window was
Code:
_CurrPrintGridLine value : 1
GridRowCount value : 1
The problem is that if i remove the IF statement and just put e.HasMorePages = True then it's stuck in a perpetual state of adding more pages when I click the print button
I need a way to set the e.HasMorePages = True for four pages then set it to false
-
Jan 4th, 2009, 04:31 PM
#6
Re: setting e.HasMorePages when Printing out a DataGridView using DataGridPrinter cla
What is this output telling you, and compare it against the 'If' check.
Code:
_CurrPrintGridLine value : 1
GridRowCount value : 1
Code:
If _CurrentPrintGridLine < GridRowCount() Then
e.HasMorePages = True
End If
Is the value of _CurrentPrintGridLine less than the value returned from the call to the GridRowCount() function?
No it is not, they both have a value of 1, therefore .HasMorePages will never be set to true, and only one page is going to be printed.
If you permanently set .HasMorePages to true, then it will carry on forever, as you have found out because you are constantly telling the app that more pages are to be printed!
You are going to have to show us what code you have in the GridRowCount function. I would guess there might be an error in there because it is returning a value of 1, and I am assuming your grid has more than one row in it.
Or, failing that, you will have to set up a counter variable that increments each time a page has been printed, and stop when it reaches a count of 4, but let's see what you have in the function first.
-
Jan 4th, 2009, 05:25 PM
#7
Thread Starter
Member
Re: setting e.HasMorePages when Printing out a DataGridView using DataGridPrinter class
Andy I seem to have gotten it working somehow. I set the initial value of GridRowCount to 0 and it seems to be fine now. Thanks for all your help!
Last edited by micki_free; Jan 4th, 2009 at 05:35 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|