如何在WPF项目中将rdlc文件添加到ReportViewer

我通过我的主窗口的XAML设计ReportViewerWPF应用程序中添加了一个ReportViewer ,我想添加一个现有的rdlc文件。

我希望我的reportviewer在启动时显示一个空的rdlc文件(没有参数),稍后从我的datagrid中选择一行(绑定到observablecollection)相应地更改其参数并显示填充的报告定义而不是空的报告定义。

我将创建一个按钮,将所选行作为命令参数和相关事件以及所有内容,我只需要能够将数据传递给报表。 我意识到这不是一个简单的问题所以我会尝试简化:

  1. 如何将现有的rdlc文件添加到ReportViewer(MVVM,WPF)?
  2. 我按下一个按钮 – >相关命令从我的observablecollection获取项目作为参数(我的数据网格中的一行) – >如何将此项目的数据部分传递给报告的未填充(或覆盖,如果填写)部分?

我希望我已经清楚了。 谢谢你的回答!

将initilizeMethod设置为具有此类报告和数据集名称的正确路径后。

 private void initializeReport() { this.mform_components = new System.ComponentModel.Container(); Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource(); this.ProductBindingSource = new System.Windows.Forms.BindingSource(this.mform_components); ((System.ComponentModel.ISupportInitialize)(this.ProductBindingSource)).BeginInit(); reportDataSource1.Name = "DataSet4"; reportDataSource1.Value = this.ProductBindingSource; this.viewerInstance.LocalReport.DataSources.Add(reportDataSource1); this.viewerInstance.LocalReport.ReportEmbeddedResource = "YourReport.rdlc"; this.viewerInstance.ZoomPercent = 95; this.windowsFormsHost1.Width = 680; ((System.ComponentModel.ISupportInitialize)(this.ProductBindingSource)).EndInit(); } 

唯一应该留下的是指定要在报表中设置的对象。

 private System.Windows.Forms.BindingSource ProductBindingSource; private void startReport() { YourClass item = (YourClass)DataGridView.SelectedItem; this.ProductBindingSource.DataSource = item; this.viewerInstance.RefreshReport(); this.viewerInstance.Refresh(); } 

几个月前,A正在发展一些想法。 然而,这里要发布很多代码,但是看看这个带有源代码的完整示例。 Advanced-Report-Viewver Codeproject