3

WPFでrdlcレポートを使用しているので、WindowsFormsHostラッパーを使用して使用しています。実行しようとしているrdlcレポートにはサブレポートが埋め込まれており、ReportViewerのSubreportProcessingイベントを使用してそのデータソースを設定しています。

Viewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LoadAccessoriesSubReport);

私の問題は、SubreportProcessingイベントが発生しないことです。埋め込まれたReportViewerコントロールを含むWPFウィンドウのイベントで定義していWindow_Loadedます。以下のxamlを参照してください。

       Title="ReportViewer" Height="1000" Loaded="Window_Loaded" Width="1000">
<Grid>
    <WindowsFormsHost Name="winHost">
        <wf:ReportViewer  Dock="Fill" Name="rptViewer">
        </wf:ReportViewer>  
    </WindowsFormsHost>                   
</Grid>

これに関する助けをいただければ幸いです。

4

7 に答える 7

8

サブレポートのパラメータを確認してください。パラメータ条件が失敗した場合、サブレポートはロードされません。Visual Studioのトレース出力も確認してください。これにより、エラーの原因となったパラメーターが示されます。

クイックチェックを実行するには、すべてのサブレポートパラメータをnullを許可するように設定します。

それは私にとってトリックでした(今、私は期待された値の代わりにnull値を取得する理由を理解する必要があります:))

于 2010-02-15T16:19:54.227 に答える
2

私は同じ問題を抱えていてReportViewer1.Reset()、イベントハンドラーをクリアしていることに気付きました。ReportViewer1.Reset()問題を解決した直後に AddHandler 行を移動します。

于 2012-05-24T17:03:45.220 に答える
1

これは、おそらく最善の解決策ではなく、うまく機能させることができた方法です.... EFとWPFを使用しています

    private void PrepareReport(ViewTravelOrderEmployees travelOrder)
    {
        entities = new PNEntities();            

        this.mform_components = new System.ComponentModel.Container();
        Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
        Microsoft.Reporting.WinForms.ReportDataSource reportDataSource2 = new Microsoft.Reporting.WinForms.ReportDataSource();

        this.ProductBindingSource = new System.Windows.Forms.BindingSource(this.mform_components);
        this.ProductBindingSource2 = new System.Windows.Forms.BindingSource(this.mform_components);            

        reportDataSource1.Name = "ViewTravelOrderEmployees";
        reportDataSource1.Value = this.ProductBindingSource;
        //DAL_Destination is Subreport -> Properties -> General -> Name in rdlc
        reportDataSource2.Name = "DAL_Destinations";
        reportDataSource2.Value = this.ProductBindingSource2;

        this.reprt.LocalReport.DataSources.Add(reportDataSource1);
        this.reprt.LocalReport.DataSources.Add(reportDataSource2);

        this.reprt.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SubreportProcessingEventHandler);            

        this.reprt.LocalReport.ReportEmbeddedResource = "PNWPF.TravelOrder.rdlc";
        string exeFolder = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.StartupPath);
        string reportPath = System.IO.Path.Combine(exeFolder, @"Reports\TravelOrder.rdlc");
        this.reprt.LocalReport.ReportPath = reportPath;

        this.ProductBindingSource.DataSource = travelOrder;            
        this.reprt.RefreshReport();             
    }

        void SubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e)
    {
        entities = new PNEntities();

        string dataSourceName = e.DataSourceNames[0];
        //query needs to be completed this is just example
        List<Destinations> destinations = entities.Destinations.ToList();            

        e.DataSources.Add(new ReportDataSource(dataSourceName, destinations));
    }

    PNEntities entities;
    private System.ComponentModel.IContainer mform_components = null;
    private System.Windows.Forms.BindingSource ProductBindingSource;
    private System.Windows.Forms.BindingSource ProductBindingSource2;

XAML

<Window x:Class="PNWPF.frmReportWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:viewer="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"
Title="frmReportWindow" Height="300" Width="300">
<Grid>
    <wfi:WindowsFormsHost Name="winfrmHost">
        <viewer:ReportViewer x:Name="reprt">

        </viewer:ReportViewer>
    </wfi:WindowsFormsHost>
</Grid>

于 2012-04-11T09:07:03.840 に答える
1

おそらくこの質問は少し古いですが、ここでも同じ問題があります.コードビハインドからデータソースを割り当てる場合は、メインレポートにデータソースを追加した後に SubreportProcessing イベントのハンドラーを追加してください。私はこのようにしました:

Dim rpDataSource As New ReportDataSource("sourceMain", myDataTable1)
Dim rpDataSourceSub As New ReportDataSource("sourceSub", myDataTable2)

ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.EnableHyperlinks = False
ReportViewer1.Reset()
Me.ReportViewer1.LocalReport.ExecuteReportInCurrentAppDomain(AppDomain.CurrentDomain.Evidence)
ReportViewer1.LocalReport.ReportPath = "Reports\report1.rdlc"
ReportViewer1.LocalReport.DisplayName = "Report" + Today.ToString("dd-MM-yyyy")
ReportViewer1.LocalReport.Refresh()

If Not ReportViewer1.LocalReport.DataSources.Contains(rpDataSource) Then
  ReportViewer1.LocalReport.DataSources.Add(rpDataSource)
End If

If Not ReportViewer1.LocalReport.DataSources.Contains(rpDataSourceSub) Then
  ReportViewer1.LocalReport.DataSources.Add(rpDataSourceSub)
End If

AddHandler Me.ReportViewer1.LocalReport.SubreportProcessing, AddressOf Me.SetSubDataSource
Me.ReportViewer1.LocalReport.Refresh()

以前に AddHandler 部分を追加していましたが、そのイベントは発生しませんでした。同じ問題を抱えている人に役立つことを願っています。

于 2011-12-09T09:57:55.567 に答える
1

メイン レポートのサブレポート コントロールとサブレポート自体の両方に、一致するパラメーターを追加します。

  1. メイン レポートでサブレポート コントロールを右クリック -> プロパティ... -> "InvoiceId" "[InvoiceId]" を追加
  2. サブレポートで -> 任意の場所をクリック -> 表示 -> レポート データ -> パラメータ -> 「InvoiceId」を追加
于 2012-02-15T02:24:57.167 に答える
0

ReportName プロパティをレポート ファイル名と一致するように設定してみてください。

于 2011-03-04T11:31:47.717 に答える
0

WPF アプリケーションで ReportViewer を使用せずに LocalReport を使用すると、同じ問題が発生しました。

しかし、親レポートからサブレポートにパラメーターとして null 値を渡そうとしていたことがわかった。

したがって、サブレポートはレンダリングを開始しませんでした。それが、イベントが発生しなかった理由です。

于 2010-01-18T21:05:36.817 に答える