SubreportProcessing Event not Firing
I'm using rdlc reports in WPF, so have done so using WindowsFormsHost wrapper. The rdlc report I'm looking for run has a subreport embedded in it, and I'm setting the data source of that using the SubreportProcessing event of the ReportViewer.
Viewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LoadAccessoriesSubReport);
My problem is that the SubreportProcessing event doesn't even get fired. I'm defining it in the Windo开发者_如何学JAVAw_Loaded
event of the WPF window which contains the embedded ReportViewer Control, see xaml below :
Title="ReportViewer" Height="1000" Loaded="Window_Loaded" Width="1000">
<Grid>
<WindowsFormsHost Name="winHost">
<wf:ReportViewer Dock="Fill" Name="rptViewer">
</wf:ReportViewer>
</WindowsFormsHost>
</Grid>
Would appreciate any help on this.
Check your subreport parameters. If a parameter condition fails, the subreport is not loaded. Also check Visual Studio trace output, it shows which parameter causes the error.
In order to perform a quick check, set all subreport parameters to allow null.
It did the trick for me (now, I just need to understand why I get a null value instead of the expected one :))
I had the same problem and found that the ReportViewer1.Reset()
was clearing the event handler. Moving the AddHandler line to immediately after the ReportViewer1.Reset()
solved the problem.
same problem here, even though probably this question is a bit old.. If you're assigning your datasources from code behind, make sure you add the handler of the SubreportProcessing event AFTER you've added the datasources to the main report. I did it this way:
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()
I was addind the AddHandler part before and that event was never fired. Hope that will help someone having the same problem.
Add matching parameters both on the subreport control on the main report and the subreport iteself.
- On the main report right click on the subreport control -> Properties... -> Add "InvoiceId" "[InvoiceId]"
- On the subreport -> click anywhere -> View -> Report Data -> Parameters -> Add "InvoiceId"
This is how i managed to make it work probably not the best solution....it uses EF and 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>
I had the same problem, using the LocalReport without using the ReportViewer in a WPF application.
But it turned out, that I was trying to pass a null value as a parameter from the parent report into the subreport.
The subreport therefore never started rendering. That was the reason that the event was not fired.
Try setting ReportName property to match the report file name.
精彩评论