10

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

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

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

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

我希望我已经清楚了。感谢您提前回答!

4

2 回答 2

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();
    }

唯一应该留下的就是指定您想要在报告中设置的对象。

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

            this.viewerInstance.RefreshReport();
            this.viewerInstance.Refresh();
        }
于 2013-07-18T19:04:03.463 回答
1

几个月前,A 正在开发类似的想法。然而,在这里发布的代码太多了,但是看看它的完整示例和源代码。 高级报告查看器代码项目

于 2013-07-17T21:23:17.127 回答