How to display multiple local reports using single reportviewer

Hi i want to display multiple reports having the same dataset and bindingsource on button clicks
rds = gcnew Microsoft::Reporting::WinForms::ReportDataSource();
rds->Name="databaseDataSet_result";
rds->Value = this->resultBindingSource;
this->reportViewer1->LocalReport->DataSources->Add(rds);
this->reportViewer1->LocalReport->ReportEmbeddedResource="Report4.rdlc";
this->reportViewer1->LocalReport->ReportPath="Report4.rdlc";

the only difference is the names of the reports which i change on each button click.
but the problem is i have 3 buttons for displaying 3 reports in the same reportviewer but only the report for the button clicked first is shown for all 3 buttons.

Regards
ansh

[806 byte] By [anshmalik] at [2008-1-1]
# 1
I read on this forum some threads stating it is not possible.So i used 3 report viewers displaying 3 different rdlc reports.
AnshulMalik at 2007-9-12 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2

I was trying to achieve a similar thing....but what I was wanting was to be able to feed an embedded report a dataset that I generate on the fly in code....and still be able to use one viewer to switch between multiple embedded reports. I was able to accomplish this by doing the following...

-First I added a new dataset [MyDataSet] item to my project via the designer....(right click project>>add>>new item>>dataset)

-I then configured my datatable[dt] in the ds...adding columns and specifying keys, datatypes...etc

-I then added(created) my various embedded reports again via the designer....

-I then designed the report using the empty dataset. I used a table to display my data....so when I looked under the properties of the table...I saw that the report identified the dataset as "MyDataSet_dt"...so in my case the name of my dataset underscore the name of the datatable...

-Next ..you can drag the viewer to your panel of choice ..or not...

-if not...then my code goes something like this....

Imports Microsoft.Reporting.WinForms

Public Class Form1

Friend WithEvents RptViewer1 as ReportViewer

Private Sub MyButton_Click(byval sender as System.Object, byval e as System.EventArgs) Handles MyButton.Click

dim ds as new MyDataSet

dim drow as DataRow = nothing

'populate the instance of the dataset...I'll actually do this via multiple db connections/querys...and roll up my data into the ds

'I show the below only for simplicity sake

drow = ds.Tables("dt").NewRow

drow.Item("MyCol1") = myValue

....

ds.Tables("dt").Rows.Add(drow)

'wipe out the Report Viewer object if needed

If Not RptViewer1 Is Nothing Then

RptViewer1.Dispose()

End If

RptViewer1 = New ReportViewer

'I snatched the below 4 lines from the designer class when I originally added the viewer control to my form...

RptViewer1.Location = New System.Drawing.Point(0, 0)

RptViewer1.Name = "RptViewer1"

RptViewer1.Size = New System.Drawing.Size(594, 452)

RptViewer1.TabIndex = 0

Me.SplitContainer1.Panel2.Controls.Add(Me.ReportViewer1)

Application.DoEvents() 'force the control to fully paint

'match the datasource name to the one you use in your embedded report...

dim RptDataSource1 as New ReportDataSource("MyDataSet_dt")

RptViewer1.LocalReport.DataSouces.Add(RptDataSource1)

'I think it's the assemblyName.reportName.rdlc....? look in the designer class and see how the dataset was instantiated...

RptViewer1.LocalReportEmbeddedResource = "AssemblyName.Report1.rdlc"

'add a few parameters if needed...

dim p as new ReportParameter("MyReportParamName", myvalue)

dim pCol() as ReportParameter = { p }

RptViewer1.LocalReport.SetParameters(pCol)

RptViewer1.RefreshReport()

End Sub

End Class

One issue I've seen with this approach is that the control will flicker when you dispose/new it.... I suppose you could use two viewer objects and toggle between the two....bringing forward one and disposing the other behind the scenes...? You could also test for which report is being generated.....so as not to dispose a viewer control when the report is the same report currently being displayed...?

Now I have to admit...I am certainly no expert...so by all means test it....

Anyway hope this helps you....

klegesdal2 at 2007-9-12 > top of Msdn Tech,Windows Forms,Windows Forms General...