Link to home
Start Free TrialLog in
Avatar of losoeos
losoeos

asked on

Crystal Reports PrintReport "-1 is not a valid value for value. value must be greater than or equal to 0."

Hi experts;

I'm making a class that sends to the printer a document after saving the GUID of the record and the type of document in a table. I've made all my reports in Crystal Reports 9 in Visual Studio 2003, so, for me it was natural to use the Crystal Report ReportViewer class inside my class in order to print the document after I save it. Also I didn't know another solution cause I don't how to catch the click event of the print button of the ReportViewer.

Initially I inherited from this class (ReportViewer) and overrided the PrintReport method but the problem remained the same. So that's why I made it in the way i present it now.

The problem is that after I save the document in the database, and then perform the PrintReport method of the CrystalReportViewer I receive this error:

A first chance exception of type 'System.ArgumentException' occurred in system.drawing.dll
Additional information: '-1' is not a valid value for 'value'.  'value' must be greater than or equal to 0.

my class definitiion is this :

Friend Class PrintRegister
       
        'Define event
        Public Event Printed(ByVal sender As Object)

        Private m_PrintType As Int64
        Private m_SYSGUID As String

        Dim m_CrystalViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer

        Public Sub New(ByVal PrintType As Int64, ByVal GUID As String)
            m_CrystalViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer
            m_PrintType = PrintType
            m_SYSGUID = GUID
        End Sub

        Public Sub New(ByVal ReportSource As Object, ByVal PrintType As Int64, ByVal GUID As String)
            m_CrystalViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer
            Me. m_PrintType = PrintType
            Me.m_SYSGUID = GUID
            m_CrystalViewer.ReportSource = ReportSource
        End Sub

        Public Sub RecordAndPrint()

            'Prepare for saving
            Dim _MyRegister As New myRegister.Register
            Dim Reg As New Register.S_PRINT_Reg
            With Reg
                .PRINTTYPE = m_PrintType
                .REGGUID = m_SYSGUID
            End With

            'Save
            _MyRegister.Save(Reg, g_SessionID)

            'Free memory
            Impresion.Dispose()

            'Print the document
            m_CrystalViewer.PrintReport()  ' <----------------------- Here is the error

            RaiseEvent Printed(Me)
        End Sub

    End Class

And this is how I call it:

Dim cr as new crptMyReport
Dim xsd as new xsdSource

xsd = ReturnData()
cr.SetDataSource(xsd)

Try

  Dim Register As New PrintRegister(cr, xsd.Tables(0).Rows(0).Item("SYSGUID"))
  Registrador.RecordAndPrint()

Catch (ex as Message)
  msgbox err.number, ex.message
End Try

Am I using a wrong approach? How can i fix this problem or do you have a better solution?

Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial