Insert subreports programmatically

Posted by: edv on 29 April 2020, 8:56 pm EST

    • Post Options:
    • Link

    Posted 29 April 2020, 8:56 pm EST

    Hi!

    I am using a licensed Version of ActiveReports 11. I am using also Section Report (Cade based):

    In the Detail_Format section I’ve defined the following:

    Dim _SubReport As arSubRerpot = Nothing
    

    Where arSubRerpot is an external report, that is in the design time three times inserted under the names arSubRerpot1, arSubRerpot2, arSubRerpot3

    The used Code looks like this:

    Dim dt As DataTable ….
    
    Dim i As Integer
    
    For Each dr As DataRow In dt.Rows
    	Select Case i
    	Case 1
    		arSubRerpot1.Report = New arSubRerpot
    		_SubReport = arSubRerpot1.Report
    	Case 2
    		arSubRerpot2.Report = New arSubRerpot
    		_SubReport = arSubRerpot2.Report
    	Case 3
    		arSubRerpot3.Report = New arSubRerpot
    		_SubReport = arSubRerpot3.Report
    	End Select
    
    	SubReport = Nothing
    	I += 1
    Next
    

    This works fine!

    Now I am having the problem, that the number of subreports is undefined, it may be 1 or 10 …

    I am looking for a way to add the subreports programmatically and not in the design time.

    Thank you in advance

  • Posted 3 May 2020, 6:57 pm EST

    Hello,

    You can add as much SubReport Control in the report in “Report_Start” event as follow:

    
    Private Sub Report_PageStart(ByVal sender As Object, ByVal e As EventArgs)
        Dim subcontrol1 As GrapeCity.ActiveReports.SectionReportModel.SubReport = New GrapeCity.ActiveReports.SectionReportModel.SubReport()
        Me.detail.Controls.Add(subcontrol1)
    End Sub
    
    

    Thanks,

    Mohit

  • Posted 3 May 2020, 8:50 pm EST

    Thank You Mohit.

    So I can add a subreport in “Report_Start”. But How can I use it in the “Detail_Format”?

    “subcontrol1” is not declared there!

    Trying something like “Me.Detail.Controls(“subcontrol1”)…” does no work too. The control ist not recognized as a subreport.

    I’ve tried in “Report_Start” something like;

    srTermDetail5.Name = “subcontrol1”

    or/and srTermDetail5.ReportName = “subcontrol1”

    But no chance!

    What’s I am doing wrong?

  • Posted 3 May 2020, 8:51 pm EST

    Sorry I mean:

    subcontrol1.Name = “subcontrol1”

    or/and subcontrol1.ReportName = “subcontrol1”

  • Posted 3 May 2020, 8:58 pm EST

    Hello,

    You can typecast the control as follow:

    Ctype(Me.Detail.Controls(“test”), GrapeCity.ActiveReports.SectionReportModel.SubReport).ReportName=“”

    Thanks,

    Mohit

  • Posted 3 May 2020, 9:59 pm EST

    Sorry but it does not work.

    “subcontrol1” is still not declared in “Detail_Format”.

  • Posted 4 May 2020, 6:21 pm EST

    Hello,

    Please refer to the attached sample. If the issue still occurs, please modify the attached sample and give back to us.

    Thanks,

    win_SubReport.zip

  • Posted 5 May 2020, 9:37 pm EST

    Hello,

    You can set the Left, TOp of the subreport control as follow:

    ```

    Dim subcontrol1 As GrapeCity.ActiveReports.SectionReportModel.SubReport = New GrapeCity.ActiveReports.SectionReportModel.SubReport()

    subcontrol1.Name = “subcontrol1”

        Me.SubReport1.Height = 1.0!
        Me.SubReport1.Left = 0!
        Me.SubReport1.Top = 0!
        Me.SubReport1.Width = 3.0!
        Me.Detail.Controls.Add(subcontrol1)
    
        Dim subcontrol2 As GrapeCity.ActiveReports.SectionReportModel.SubReport = New GrapeCity.ActiveReports.SectionReportModel.SubReport()
        subcontrol2.Name = "subcontrol2"
    
        Me.SubReport2.Height = 1.0!
        Me.SubReport2.Left = 0!
        Me.SubReport2.Top = 1.0!
        Me.SubReport2.Width = 3.0!
        Me.Detail.Controls.Add(subcontrol2)
    
    
    Thanks,
    Mohit
  • Posted 5 May 2020, 10:22 pm EST

    Super!

    What does “!” means?

  • Posted 5 May 2020, 10:32 pm EST

    It is the syntax to assign the value to size/location properties control of SectionReport.

  • Posted 5 May 2020, 10:51 pm EST

    Thank you very much.

  • Posted 5 May 2020, 11:39 pm EST

    Sorry I have another question:

    I would like to add n subreports, where n is only known in runtime !

    something like that:

    for i = 1 to n
    '...
    ' Add sub report i
    
    next i
    

    Is there is a way to do this?

    Dim subcontrol(i) As GrapeCity.ActiveReports.SectionReportModel.SubReport = New GrapeCity.ActiveReports.SectionReportModel.SubReport()
            subcontrol(i).Name = "subcontrol" & i
    

    An array of controls?

  • Posted 6 May 2020, 4:21 pm EST

    Hello,

    You can use the following line of code:

    For I As Integer = 0 To N
               Dim subcontrol As GrapeCity.ActiveReports.SectionReportModel.SubReport = New GrapeCity.ActiveReports.SectionReportModel.SubReport()
               subcontrol.Name = "subcontrol" + I.ToString()
               Me.Detail.Controls.Add(subcontrol)
           Next
    

    After that, you can access the subcontrol in the detial section through its name.

    Thanks,

    Mohit

  • Posted 6 May 2020, 7:18 pm EST

    Thank you very much for the super support.

  • Posted 18 May 2020, 6:08 pm EST

    Thank you very much Mohit. It works!

    tubemate mobdro

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels