Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying info to user as Crystal Report loads 1

Status
Not open for further replies.

BFarley

Programmer
May 22, 2008
43
US
I've got a form named frmReportViewer, containing a CrystalReportViewer named crvReportViewer.

frmReportViewer is an all-purpose form, displaying whatever Crystal Report I tell it to programmatically on a button click event from various forms.

Some sample code:

Code:
        Dim cur As Cursor = Nothing
        Dim frm As New frmReportViewer
        Dim crv As CrystalReportViewer = frm.crvReportViewer
        Dim crpt As ReportDocument = New ReportDocument

        Try

            Dim intCounter As Integer = 0
            Dim strAccounts As String = Nothing
            Dim strCompany As String = Nothing
            Dim strReportName As String = "myreport.rpt"

            cur = Me.Cursor

            Me.Cursor = Cursors.WaitCursor

            ' Load report file
            crpt.Load(strReportName)

            Dim ctblCurrent As Table
            Dim tlogCurrent As TableLogOnInfo


            ' Supply logon info
            For Each ctblCurrent In crpt.Database.Tables
                tlogCurrent = ctblCurrent.LogOnInfo
                With tlogCurrent.ConnectionInfo
                    .ServerName = My.Settings.JamisSqlServerName
                    .UserID = <username>
                    .Password = <password>
                    .DatabaseName = <dbname>
                End With
                ctblCurrent.ApplyLogOnInfo(tlogCurrent)
            Next ctblCurrent

            Dim crParameterDiscreteValue As ParameterDiscreteValue
            Dim crParameterFieldDefinitions As ParameterFieldDefinitions
            Dim crParameterFieldLocation As ParameterFieldDefinition
            Dim crParameterValues As ParameterValues

            ' Parameter 1: BeginningDate
            crParameterFieldDefinitions = crpt.DataDefinition.ParameterFields
            crParameterFieldLocation = crParameterFieldDefinitions.Item("BeginningDate")
            crParameterValues = crParameterFieldLocation.CurrentValues
            crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
            crParameterDiscreteValue.Value = Format(dtpStartDate.Value, "yyyyMMdd")
            crParameterValues.Add(crParameterDiscreteValue)
            crParameterFieldLocation.ApplyCurrentValues(crParameterValues)



            ' Set viewer's source to this report
            crv.ReportSource = crpt



            frm.Show()

        Catch ex As Exception
            MessageBox.Show("Error: " + ex.ToString(), Me.Name & ": btnCreateReport_Click", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation)
        Finally
            Me.Cursor = cur
        End Try

As you can see the hourglass cursor is turned on before the processing starts, and then in the "Finally" portion of Try..Catch, it's reset to the default.

When reports are smaller, they seem to appear in frmReportViewer almost immediately. However, on longer reports, the user is presented with a blank form as data loads.

Is there a way to determine when the data has finished loading into crvReportViewer? And perhaps delay showing frmReportViewer until this has happened? Or display an hourglass after frmReportViewer loads, until crvReportViewer is complete with data?

Thanks in advance.

Bryant Farley

"The Dude Abides
 
There are a several ways, but the most straight forward is if the code that runs the report is in the forms load event it will occur before the form shows.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
That makes sense. Is there a way to continue using just a single report viewer form & flexible way of passing the parameters, connection info, etc? I would prefer not to have a separate form for each report if possible. I did find one example at but I am not certain whether it would address the load time issue.

Would the report's load time be faster if I grabbed the SQL data into a typed dataset, rather than asking CR to pull the data as it is now?

Bryant Farley

"The Dude Abides
 
There again there is a lot of different ways. Even with it in the Load event you don't have to make a form for each. You could use global variables. You could add a New() to the form, pass it a variable, and then create an instance of your form. And so on. None of this will effect the load time it just bypasses the blank form look.

Just looked at the link. That would be an "And so on". There are just so many different ways you could do it. Again it isn't going to make anything faster just bypass the blank form look. Not for crystal reports, but I've used that way of doing it on other projects I've worked on. A way like that also insures you don't have 6 or 60 reports open at once.

Would the report's load time be faster if I grabbed the SQL data into a typed dataset, rather than asking CR to pull the data as it is now?
That I don't know. All I could suggest is try it and see.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top