【问题标题】:C# report error when calling multiple reports from within WPF project in the same solution在同一解决方案中从 WPF 项目中调用多个报告时 C# 报告错误
【发布时间】:2011-11-15 16:42:06
【问题描述】:

我目前正在尝试使用多个报告,以便当用户从 WPF 应用程序的上下文菜单中选择一个项目时,报告表单会与所选报告一起出现。如果从上下文菜单中选择了每周,则需要在报告表单中显示每周报告。

我没有收到编译时错误,但我的报告查看器显示以下“本地报告处理期间发生错误。尚未指定报告'Reports.Report3.rdlc' 的报告定义。”

我在点击上下文菜单项时使用下面的代码

Reports.Form1 Reports = new Reports.Form1();
                Reports.reportViewer1.Reset();
                Reports.reportViewer1.LocalReport.DataSources.Clear();
                ReportDataSource reportDataSource1 = new ReportDataSource();
                Reports.SpecificationsTableAdapter.Fill(Reports.RocketToolsDataSet.Specifications);
                reportDataSource1.Name = "TestDataSet";
                reportDataSource1.Value = Reports.SpecificationsBindingSource;
                Reports.reportViewer1.LocalReport.DataSources.Add(reportDataSource1);
                Reports.reportViewer1.LocalReport.ReportEmbeddedResource = "Reports.Report3.rdlc";
                Reports.reportViewer1.Name = "reportViewer1";
                Reports.reportViewer1.RefreshReport();
                Reports.Show();
                loading.Close();

报告表单的项目名称为 Reports,WPF 应用程序的项目名称为 RocketTools。我在我的 WPF 项目中引用了 Reports 项目。如果报告是在报告表单中加载的默认设置,则加载正常。但是当我尝试在我的 WPF 应用程序中更改表单加载的设置时,我得到了上面的错误。

谁能帮帮我

【问题讨论】:

    标签: c# wpf reporting multiple-projects


    【解决方案1】:

    通过使用 windowsformhosting 而不是引用另一个项目来解决问题。

    XAML 代码如下所示,然后通过向项目中添加新项目并在创建报告窗口实例时使用我原始问题中的代码手动创建表适配器和数据集。

    <Window x:Class="RocketTools.Reports"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:viewer="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"
            Title="Reports" Height="691" Width="1117" Loaded="Window_Loaded" Closed="Window_Closed" WindowStartupLocation="CenterOwner">
        <Grid x:Name="ReportGrid">
            <WindowsFormsHost Margin="12" Name="windowsFormsHost1">
                <viewer:ReportViewer x:Name="viewerInstance"></viewer:ReportViewer>
            </WindowsFormsHost>
        </Grid> </Window>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-08
      • 1970-01-01
      相关资源
      最近更新 更多