4

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 Window_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.

2
  • I have the same problem. I have not found a solution yet...
    – jbandi
    Jan 18, 2010 at 12:06
  • While not directly the question I had, the details in question answered my question I had. Thanks! +1
    – Mike Wills
    Jun 2, 2010 at 19:23

7 Answers 7

10

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 :))

1
  • Your answer guide me to the right direction, thanks. Now I know that Any problem with the parameters in the Main report and the SubReport(i.e. the report file which is used as the subreport and the subreport parameters in subreport properties) would prevent the event's raise. May 24, 2013 at 9:18
2

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.

1

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.

1

Add matching parameters both on the subreport control on the main report and the subreport iteself.

  1. On the main report right click on the subreport control -> Properties... -> Add "InvoiceId" "[InvoiceId]"
  2. On the subreport -> click anywhere -> View -> Report Data -> Parameters -> Add "InvoiceId"
0

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.

0

Try setting ReportName property to match the report file name.

0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.