Print Page | Close Window

more than 1 report bind to CrystalReportViewer

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Writing Code
Forum Discription: .NET programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=1502
Printed Date: 03 May 2025 at 5:53pm


Topic: more than 1 report bind to CrystalReportViewer
Posted By: RealQMan
Subject: more than 1 report bind to CrystalReportViewer
Date Posted: 12 Oct 2007 at 2:20pm
Hi All,

There is a question for those who are familiar on working with crystal reports in VS 2005. So, it's possibly you worked with CrystalReportViewer object used as a useful tool to view report. I know how to bind 1 report to the crystalreportviewer for display, but there are probably 1 or more reports that will need to display simulataneously. The most obvious and straightforward solution is to include as much crystalreportviewer objects as the report and bind them accordingly. But isn't it more efficient if i can just bind 1 or more reports to just 1 crystalreportviewer object. How do i write it?





Replies:
Posted By: BrianBischof
Date Posted: 15 Oct 2007 at 9:18am
You are right that you will have to use multiple viewer objects. CR only allows one report per viewer object.

-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: wattsjr
Date Posted: 15 Oct 2007 at 3:05pm
Hi RealQMan,
 
I've taken a slightly different approach, so I don't know if this is the kind of thing that you're asking about, but it works for me. Now, I'm using VB2003, so if that makes a difference just ignore the rest.
 
What I did was to:
Create my reports and save them separate (not imbnedded) from the VB app.
 
Create a sub-form and called it frm(application)Report,
 
Added a CrystalReportViewer, a reportDocument and a OleDbConnection to the form.
 
Sized the Viewer to fill the whole form
 
Then I coded a Sub-routine with the following:
 
Private Sub ....vViewer.....
' create a virtual copy of the form
Dim vAppNameReport As New frmAppNameReport()
 
' Pass the vForm te CR.rpt path & name
vAppNameReport.CrystalReportViewer1.ReportSource = crReportDocument
 
' Check for Selection criteria in the report. If there is any, merge it with the Selection criteria from the VB App.
If Len(crReportDocument.RecordSelectionFormula) > 5 Then
    If Len(Select_String) > 1 Then
        vAppNameReport.CrystalReportViewer1.SelectionFormula = "(" &    crReportDocument.RecordSelectionFormula & ") AND " & Select_String
    Else
        vAppNameReport.CrystalReportViewer1.SelectionFormula = "(" &  crReportDocument.RecordSelectionFormula & ")"
    End If
  Else : vAppNameReport.CrystalReportViewer1.SelectionFormula =  Select_String
 End If
 
' Pass various properties to the form
vAppNameReport.Text = gReportName
vAppNameReport.CrystalReportViewer1.Dock = DockStyle.Fill
vAppNameReport.Visible = True
vAppNameReport.BringToFront()
vAppNameReport.CrystalReportViewer1.Visible = True
vAppNameReport.CrystalReportViewer1.BringToFront()
 
Then I created a button for each report and called the sub-routine from the buttons subroutine with the following:
 
gSelString = txtComplaintID.Text
gReportSource = gfilePath & "CRreportname.rpt"
gReportName = "Title"
 
' Called the vViewer sub-routine, passing it various parms wich were used to supply login criteria
' to other parts of the sub-routine.
Me.SendToBack()
vViewer(gID, gPWD, gServerName)
 
This setup gives me the ability to view several reports at a time, each one using a virtual viewer.
I hope this is useful to you,


-------------
-jrw


Posted By: RealQMan
Date Posted: 09 Nov 2007 at 11:39am
hi, i've been working on other reports, but now i have time to get back to print multiple reports...

Your virtual viewer is more robust and flexible than mine was. I had a similar idea before posting, which was to display one report with one virtual viewer. Basically one to one relationship.. the scenario i am facing will require all the reports to be view at once... So, if there's 5 reports for 5 different customers, than all 5 are view... Using the code we have now, it will require 5 instance of virtual viewer. The application takes a performance hit dramatically.

Thanks anyways, it was a great post.



Print Page | Close Window