我有一個reportViewer和多個報告(例如Report1.rdlc,Report2.rdlc,ecc), 我怎麼能以編程方式在它們之間切換?以編程方式將報告分配給我的reportViewer
我能夠分配不同的報告,但是當我執行程序時,它說我需要分配數據來源,我該如何做到這一點?
編輯:這是到目前爲止我的代碼:
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();
}
新版本仍然無法正常工作,當我運行它,它仍然要求提供數據來源。
我已經嘗試了不同的組合,但沒有一個可以工作。 組合,如:
var binding = new BindingSource();
binding.DataSource = this.NGStoreV2DataSet.mag2;
ReportDataSource rds = new ReportDataSource("NGStoreV2DataSet", binding);
或
ReportDataSource rds = new ReportDataSourc("NGStoreV2DataSet", this.mag2BindingSource);
編輯:我終於設法解決這個問題!我使用了錯誤的數據集(而不是報表數據集至極NGStoreV2DataSet是數據集1) 謝謝既tezzo和哈迪的大力幫助;)
你是如何設置它的?你的實施在哪裏? – felipekm
編輯的問題 – Spartan