Gáb*_*kás 9 c# wpf reportviewer rdlc mvvm
我通过主窗口的设计者ReportViewer
在WPF
应用程序中添加了一个XAML
,我想添加一个现有的rdlc文件.
我希望我的reportviewer在启动时显示一个空的rdlc文件(没有参数),稍后从我的datagrid中选择一行(绑定到observablecollection)相应地更改其参数并显示填充的报告定义而不是空的报告定义.
我将创建一个按钮,将所选行作为命令参数和相关事件以及所有内容,我只需要能够将数据传递给报表.我意识到这不是一个简单的问题所以我会尝试简化:
我希望我已经清楚了.谢谢你提前回答!
小智 3
使用正确的报告路径和数据集名称设置 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();
}
Run Code Online (Sandbox Code Playgroud)
唯一应该留下的就是指定您想要在报告中查看的对象。
private System.Windows.Forms.BindingSource ProductBindingSource;
private void startReport()
{
YourClass item = (YourClass)DataGridView.SelectedItem;
this.ProductBindingSource.DataSource = item;
this.viewerInstance.RefreshReport();
this.viewerInstance.Refresh();
}
Run Code Online (Sandbox Code Playgroud)