2009-12-02 215 views
3

我在WPF中使用rdlc報告,所以使用WindowsFormsHost包裝器來完成。我正在查找的rdlc報告中嵌入了一個子報表,我使用ReportViewer的SubreportProcessing事件設置了該報表的數據源。SubreportProcessing Event not Firing

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

我的問題是SubreportProcessing事件甚至沒有被解僱。我定義它在Window_Loaded事件,包含嵌入ReportViewer控件WPF窗口的,請參見下面的XAML:

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

將不勝感激任何幫助。

+0

我有同樣的問題。我還沒有找到解決方案...... – jbandi 2010-01-18 12:06:33

+0

雖然不是直接的問題,但有問題的細節回答了我的問題。謝謝! +1 – 2010-06-02 19:23:04

回答

0

我有同樣的問題,使用LocalReport而不使用WPF應用程序中的ReportViewer。

但事實證明,我試圖將一個空值作爲參數從父報告傳遞到子報表中。

因此,該子報表從未開始渲染。這是事件未被解僱的原因。

6

檢查您的子報表參數。如果參數條件失敗,則不加載子報表。 還檢查Visual Studio跟蹤輸出,它顯示哪個參數導致錯誤。

爲了執行快速檢查,請將所有子報告參數設置爲允許爲空。

它爲我做的伎倆(現在,我只需要明白,爲什麼我得到一個空值,而不是預期的一個:))的

+0

你的回答引導我走向正確的方向,謝謝。現在我知道主報表和子報表中的參數有任何問題(即用作子報表和子報表屬性中的子報表參數的報表文件)都會阻止事件的發生。 – VahidNaderi 2013-05-24 09:18:14

0

嘗試設置REPORTNAME屬性相匹配的報告文件名。

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部分,並且該事件從未被解僱。希望能幫助有同樣問題的人。

1

在主報表的子報表控件和子報表iteself上添加匹配參數。

  1. 在主報告中右擊報表控件 - >屬性 - >添加 「InvoiceId」 「[InvoiceId]」
  2. 在報表 - >點擊任意位置 - >查看 - >報告數據 - >參數 - >添加「InvoiceId」
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> 

2

我有同樣的問題,發現ReportViewer1.Reset()被清除的事件處理程序。在ReportViewer1.Reset()解決了問題後,立即將AddHandler行移動到。