none
SubReports don't show if I load definition file from a stream RRS feed

  • Question

  • Hi,
    I have a problem with Subreports when loading RDLC's from a stream but not when loading them directly.
    In the following code if the (1) statement below 'Option1 is used/uncommented and (2) statements below 'Option2 are commented out then all works Ok and SubreportProcessingEventHandler function is called.

    If however Option1 statement is commented out and Option2 statements are used/uncommented then SubReport doesn't work nor does the SubreportProcessingEventHandler function get called.

    Instead of SubReport details I get an error message "Error: Subreport could not be shown".

    Any asistance would be much appreciated.

    Thanks,
         Michael

    P.S. I get the following warning in the Immediate Window.
    "Warning: An error occurred while executing the subreport ‘srepInclusions’: The report definition for report 'rptInclusions' has not been specified (rsErrorExecutingSubreport)"
    srepInclusions is teh name of my Subreport control in ReportViewer1.


    Code Snippet

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.ReportViewer1.Reset()

        Dim SubSectionsBindingSource As New BindingSource
        SubSectionsBindingSource.DataSource = m_SubSections

        Const REPORT_NAME As String = "MySubReport_Example.rptSubSections.rdlc"
        Const SUBREPORT_NAME As String = "MySubReport_Example.rptInclusions.rdlc"

        '---Option1---
        'Me.ReportViewer1.LocalReport.ReportPath = Replace(My.Application.Info.DirectoryPath, "bin\Debug", "") & _

            "\rptSubSections.rdlc"       

        '---Option2---   

        Me.ReportViewer1.LocalReport.LoadReportDefinition( _

           Me.GetType.Assembly.GetManifestResourceStream(REPORT_NAME))
        Me.ReportViewer1.LocalReport.LoadSubreportDefinition( _

           SUBREPORT_NAME, Me.GetType.Assembly.GetManifestResourceStream(SUBREPORT_NAME))

        AddHandler Me.ReportViewer1.LocalReport.SubreportProcessing, AddressOf SubreportProcessingEventHandler
        Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("MySubReport_Example_SubSection", _

           SubSectionsBindingSource))
        Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("MySubReport_Example_SubSections", _

           SubSectionsBindingSource))

        Me.ReportViewer1.RefreshReport()
    End Sub




     
    Tuesday, February 26, 2008 11:45 PM

Answers

  • You've got all of the information in your post... you're just missing one minor item.  When you call LoadSubreportDefinition, the name of the subreport should not be the name of the file.  When you are loading from a stream, the viewer has no concept of files.  The subreport definition could just as easily be generated on the fly and only exist in memory.  The name you want to supply is the name as it appears in the parent report definition.  In this case, as indicated by the error message, the name you want to pass in to LoadSubreportDefinition is "rptInclusions".

     

    By the way, for your case, you might consider using the ReportViewer.LocalReport.ReportEmbeddedResource property to automatically load the resource from the assembly manifest.  You shouldn't need to supply the subreport separately in that case.

    Thursday, February 28, 2008 2:05 AM
    Moderator

All replies

  • You've got all of the information in your post... you're just missing one minor item.  When you call LoadSubreportDefinition, the name of the subreport should not be the name of the file.  When you are loading from a stream, the viewer has no concept of files.  The subreport definition could just as easily be generated on the fly and only exist in memory.  The name you want to supply is the name as it appears in the parent report definition.  In this case, as indicated by the error message, the name you want to pass in to LoadSubreportDefinition is "rptInclusions".

     

    By the way, for your case, you might consider using the ReportViewer.LocalReport.ReportEmbeddedResource property to automatically load the resource from the assembly manifest.  You shouldn't need to supply the subreport separately in that case.

    Thursday, February 28, 2008 2:05 AM
    Moderator
  • Hi Brian,
    Thanks a million for that, it worked like a charm and you definitely saved me some hairs on my head.
    That may not sound much but it's a lot when you don't have many left.

    /Michael

    Thursday, February 28, 2008 1:15 PM
  • For the life of me, I can't get this to work. I know this is pretty old thread, but it's the error i am getting, but I am fairly new to .Net/C#/RDLC.  My code is very simular to the VB code above. Hoever, I am still getting the same error.  my Subreport Properteis are as follows: "Name: ReportData" & "Use this report as a subreport:  SubReportData" 

    Assembly myAssembly = Assembly.LoadFrom("MyAssemblyName");
    
    Stream myStream = myAssembly.GetManifestResourceStream("ReportTesting.MainReport.rdlc");
    
    Stream myStream1 = myAssembly.GetManifestResourceStream("ReportTesting.SubReport.rdlc");
    
    
    reportViewer.LocalReport.LoadReportDefinition(myStream);
    
    reportViewer.LocalReport.DataSources.Add(MyData);
    
    reportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(MySubReportEventHandler);
    
    reportViewer.LocalReport.LoadSubreportDefinition("SubReportData", myStream1);
    
    reportViewer.LocalReport.SetParameters(myRDSParms);
    
    reportViewer.RefreshReport();
    
    
    public void MySubReportEventHandler(object sender, SubreportProcessingEventArgs e)
            {
                e.DataSources.Add(new ReportDataSource("MyReportDetail", MyData));
            }
    
    
    

    TIA


    Tuesday, April 26, 2016 12:14 PM