SubreportProcessing not burning event

I use rdlc reports in WPF, so I did it using the WindowsFormsHost shell. The rdlc report that I am looking to run has a subregister built into it, and I set the data source using the SubreportProcessing ReportViewer event.

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

My problem is that the SubreportProcessing event does not even fire. I define it in Window_Loadeda WPF window event that contains a ReportViewer built-in 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>

Thank you for your help.

+3
source share
7 answers

. , . Visual Studio, , .

, null.

( , :))

+6

, , ReportViewer1.Reset() . AddHandler ReportViewer1.Reset() .

+2

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

, .

  • → ... → "InvoiceId" "[InvoiceId]"
  • → → → → → "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>

+1

, LocalReport ReportViewer WPF.

But it turned out that I was trying to pass a null value as a parameter from the parent report to the subreport.

So the subreport never started rendering. It is for this reason that the event was not fired.

0
source

Try setting the ReportName property to match the name of the report file.

0
source

Source: https://habr.com/ru/post/1724533/


All Articles