0

私は現在、複数のレポートを使用しようとしています。これにより、ユーザーが WPF アプリケーションのコンテキスト メニューから項目を選択すると、選択したレポートと共にレポート フォームが表示されます。たとえば、コンテキスト メニューから週次レポートを選択した場合、週次レポートをレポートフォーム。

コンパイル時エラーは発生しませんが、レポート ビューアーには次のように表示されます。

コンテキストメニュー項目をクリックすると、以下のコードを使用しています

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 アプリケーション内でフォームが読み込まれる設定を変更しようとすると、上記のエラーが発生します。

誰か助けてください

4

1 に答える 1

0

別のプロジェクトを参照するのではなく、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>
于 2011-11-18T06:19:04.707 に答える