SubreportProcessing Event not Firing
我在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>
将不胜感激任何帮助。
我有同样的问题,使用LocalReport而不使用WPF应用程序中的ReportViewer。
但事实证明,我试图将一个空值作为参数从父报告传递到子报表中。
因此,该子报表从未开始渲染。这是事件未被解雇的原因。
检查您的子报表参数。如果参数条件失败,则不加载子报表。 还检查Visual Studio跟踪输出,它显示哪个参数导致错误。
为了执行快速检查,请将所有子报告参数设置为允许为空。
它为我做的伎俩(现在,我只需要明白,为什么我得到一个空值,而不是预期的一个:))的
你的回答引导我走向正确的方向,谢谢。现在我知道主报表和子报表中的参数有任何问题(即用作子报表和子报表属性中的子报表参数的报表文件)都会阻止事件的发生。 – VahidNaderi 2013-05-24 09:18:14
尝试设置REPORTNAME属性相匹配的报告文件名。
同样的问题在这里,即使这个问题可能有点老.. 如果你从后面的代码分配你的数据源,请确保你添加了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部分,并且该事件从未被解雇。希望能帮助有同样问题的人。
在主报表的子报表控件和子报表iteself上添加匹配参数。
- 在主报告中右击报表控件 - >属性 - >添加 “InvoiceId” “[InvoiceId]”
- 在报表 - >点击任意位置 - >查看 - >报告数据 - >参数 - >添加“InvoiceId”
这就是我设法使它工作可能不是最好的解决方案....它采用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>
我有同样的问题,发现ReportViewer1.Reset()
被清除的事件处理程序。在ReportViewer1.Reset()
解决了问题后,立即将AddHandler行移动到。
我有同样的问题。我还没有找到解决方案...... – jbandi 2010-01-18 12:06:33
虽然不是直接的问题,但有问题的细节回答了我的问题。谢谢! +1 – 2010-06-02 19:23:04