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

Assign a report dynamically to a reportViewer via code

3 Answers 326 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Shirya
Top achievements
Rank 1
Shirya asked on 08 Oct 2008, 03:59 PM
Hello, 
(sorry if my english isn't  good, i'll try to explain as clear as possible)
When i want to assign a report to a report viewer via code, i do it like that:
Me.ReportViewer1.report = new ReferenceReport.Report1 


ReferenceReport is my dll, who contains report1, report2 and report 3

In my form, i have a combobox that let you choose between Report1, report2, report3. So you can view the report you want
So here is my problem: how can i assign the right report to my reportViewer (via Code)
with the Winforms.ReportViewer i could do this by changing the reporPath, but with telerik reportViewer, i don't know how.. Can you help me?
thanx,
i hope i was clear enough


3 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 09 Oct 2008, 08:06 AM
Hello Shirya,

You can use exactly the same code to change the Report shown in the ReportViewer. What is also needed for the Win ReportViewer is calling the RefreshReport() method that would show the report in the viewer automatically. Otherwise you would have to click on the Refresh button in the ReportViewer in order to see the newly loaded report.

Best wishes,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Shirya
Top achievements
Rank 1
answered on 09 Oct 2008, 03:28 PM
Hello,
Thank you for the answer.
But what I wanted to know was if there is a way to do it dynamically.
In the future, i will have many reports, and i don't want something like that:

If the user select report1
        ReportViewer.report = new ReferenceReport.Report1

If the user select report2
        ReportViewer.report = new ReferenceReport.Report2

If the user select report3
        ReportViewer.report = new ReferenceReport.Report3

...
If I have 100 reports it's becoming heavy.

I think I found something with the Reflection.Assembly:
Dim extAssembly As Assembly Assembly = Assembly.LoadFrom(currentDirectory + "\ReferenceReport.dll")  
Dim test As Telerik.Reporting.Report = extAssembly.CreateInstance("ReferenceReport." + cbReports.SelectedText, True)  
 
Me.ReportViewer.Report = test 

Or is there another way? more "clean"?
0
Steve
Telerik team
answered on 09 Oct 2008, 04:02 PM
Hi Shirya,

This is a good solution as long as you're not going to host your app/site in a limited trust environment.

Best wishes,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Shirya
Top achievements
Rank 1
Answers by
Steve
Telerik team
Shirya
Top achievements
Rank 1
Share this question
or