Results 1 to 10 of 10

Thread: [RESOLVED] setting e.HasMorePages when Printing out a DataGridView using DataGridPrinter class

Hybrid View

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2008
    Posts
    61

    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?

  2. #2
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    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.
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2008
    Posts
    61

    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

  4. #4
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    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.
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2008
    Posts
    61

    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.

  6. #6
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: [RESOLVED] setting e.HasMorePages when Printing out a DataGridView using DataGridPrinter class

    The function GridRowCount() should be returning the total number of records in your data table - this is what it uses to decide whether or not it has reached the last record. If it is returning 0 (or 1) and your data table has more than 1 record then something is amiss.

    The code works best if the DataSource of the data grid being printed is a DataTable class - can you try putting your MSAccess data in a Datatable and then using that maybe?

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