I have a ReportViewer and several reports (ex Report1.rdlc, Report2.rdlc, ecc), how can I switch between them programmatically?
I managed to assign different reports, but when I run the program, it says that I need to assign data sources, how can I do this?
EDIT: Here is my code:
public Report() { InitializeComponent(); this.View_StatoMagTableAdapter.Fill(this.NGStoreV2DataSet.View_StatoMag); this.mag2TableAdapter.Fill(this.NGStoreV2DataSet.mag2); this.mag2BindingSource.DataMember = "mag2"; this.mag2BindingSource.DataSource = this.NGStoreV2DataSet; } private void reportViewer1_Load(object sender, EventArgs e) { this.reportViewer1.Reset(); var binding = new BindingSource(); binding.DataSource = this.NGStoreV2DataSet.mag2; ReportDataSource rds = new ReportDataSource("NGStoreV2DataSet", binding); this.reportViewer1.LocalReport.DataSources.Clear(); this.reportViewer1.LocalReport.DataSources.Add(rds); this.reportViewer1.LocalReport.ReportEmbeddedResource = "ReportViewerForm.Report2.rdlc"; this.reportViewer1.RefreshReport(); }
The new version still does not work, when I run the program, it still asks for the origin of the data.
I already tried different combinations, but none of this works. combinations:
var binding = new BindingSource(); binding.DataSource = this.NGStoreV2DataSet.mag2; ReportDataSource rds = new ReportDataSource("NGStoreV2DataSet", binding);
or
ReportDataSource rds = new ReportDataSourc("NGStoreV2DataSet", this.mag2BindingSource);
EDIT: I finally managed to solve it! I used the wrong DataSet (NGStoreV2DataSet instead of the report dataset, which is DataSet1) Thanks both tezzo and Hadi for a lot of help;)
source share