问题描述
我已经通过我的主窗口的XAML设计加入一个WPF应用程序一的ReportViewer,我想现有的RDLC文件添加到它。我有一个很长的谷歌会,我一直无法找到工作方法。我想我的ReportViewer显示一个空文件RDLC(不带参数)上启动的,后来在从我的DataGrid中选择行(绑定到一个ObservableCollection)相应地改变其参数,并显示填充报表定义,而不是空单。我会与所选行作为commandparameter和相关事件,一切按钮,我只需要能够将数据传递到报告中。我意识到这不是一个简单的问题,所以我会尽量简化:
I've added a reportviewer in a wpf app via the xaml designer of my main window and I'd like to add an existing rdlc file to it. I've had a very long google session and I've been unable to find a working method. I'd like my reportviewer to show an empty rdlc file (without the parameters) on startup, and later upon selecting a row from my datagrid (bound to an observablecollection) change its parameters accordingly and show the filled report definition instead of the empty one. I'll make a button with the selected row as commandparameter and the relevant events and everything, I just need to be able to pass data to the report. I realize it is not an easy question so I'll try to simplify:
- 如何将现有的RDLC文件添加到的ReportViewer(MVVM ,WPF)
- 我按下一个按钮 - >相关命令从我的ObservableCollection作为参数(在我的数据网格中的行)获取项目 - >如何这个项目的数据部分传递到未填充(或覆盖仿佛充满当然)报告的部分?
我希望我已经清楚了。感谢提前答案!
I hope I've been clear. Thanks for the answer in advance!
推荐答案
在您设置initilizeMethod用正确的路径,报告和数据集的名字是这样的
After you set up your initilizeMethod with correct path to the report and dataset name something like this.
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();
}
只有应留给被specifing要本身在对象的事情你。报告
Only thing that should be left is specifing the object you want to se in your report.
private System.Windows.Forms.BindingSource ProductBindingSource;
private void startReport()
{
YourClass item = (YourClass)DataGridView.SelectedItem;
this.ProductBindingSource.DataSource = item;
this.viewerInstance.RefreshReport();
this.viewerInstance.Refresh();
}
这篇关于如何RDLC文件添加到的ReportViewer在WPF项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!