This is a migrated thread and some comments may be shown as answers.

Reusing the ReportViewer and Winform for Multiple reports

5 Answers 187 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kerry
Top achievements
Rank 1
Kerry asked on 02 Apr 2012, 05:29 AM
Hello, 

I have a number of reports, I do not wish to create a viewer for each report, can I reuse the same ReportViewer and the winform for multiple reports by creating properties that pass in the Report to instantiate to the Winform.  I've created a separate library for my reports and now wish to instantiate my reports in the one viewer.  Is it good practice to instantiate my Report in a calling form and then pass it to the Winform that holds the viewer, cast it to a (Telerik.Reporting.IReportDocument) object and set the ReportViewers REPORT property.

Using Reporting Q3 2011

Thanks,

Kerry

5 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 02 Apr 2012, 12:01 PM
Hello Kerry,

Yes this is correct approach and we do the same in our Visual Studio examples installed with the product.

Regards,
Steve
the Telerik team
NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
0
Kerry
Top achievements
Rank 1
answered on 02 Apr 2012, 12:41 PM
Hello,

Yes I saw some of the code snippets on the forum which use IReportDocument 
 however I notice that when using IReportDocument we lose access to some of the properties available when instantiating the report such as rpt.ReportParameters["parameterName"].Value and rpt.Datasource etc.  Can you direct me to examples which still use they properties along with IReportDocument.

Thank You,

Kerry
 
0
Steve
Telerik team
answered on 03 Apr 2012, 02:10 PM
Hello Kerry,

In case you are sure that the viewer would show a single report (not a report book) and you need to access its properties, you can always cast to Telerik.Reporting.Report type and use its respective properties.

Greetings,
Steve
the Telerik team
NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
0
Kerry
Top achievements
Rank 1
answered on 03 Apr 2012, 10:35 PM
H Steve, 

Yes it is a single report however if I cast the variable as the ReportType I get an error trying to cast the same variable as a different ReportType.  I'm trying to achieve this using one block of code in on ReportViewer.

switch (_rptType)
            {
                case 1:
                    rpt = new ClientTrustLedger(eFirmSetting, dbConnect);
                    ClientTrustLedger rpt2 = (ClientTrustLedger)rpt;
                    break;
                case 2:
                    rpt = new DepositSlipReport(eFirmSetting,dbConnect);
                    DepositSlipReport rpt2 = (DepositSlipReport)rpt;
                    rpt2.ReportParameters["DepositNo"].Value = DepositNo;
                    break;
                default:
                    rpt = new ClientTrustLedger(eFirmSetting, dbConnect);
                    break;
            }
            
            this.reportViewer1.Report = rpt2;
            this.reportViewer1.RefreshReport();


If you can direct me to smaple code that would be helpful.

Thanks,


Kerry
0
Steve
Telerik team
answered on 06 Apr 2012, 11:00 AM
Hello Kerry,

There is a much cleaner solution to initialize a report from a predefined list by using reflection, check the attached project.

Greetings,
Steve
the Telerik team
NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
Tags
General Discussions
Asked by
Kerry
Top achievements
Rank 1
Answers by
Steve
Telerik team
Kerry
Top achievements
Rank 1
Share this question
or