Adding subreports at runtime?


03-08-2010, 12:11 PM
is it possible to add subreports at runtime without having a design time placeholder?

Re: Adding subreports at runtime?


03-08-2010, 11:53 PM
Hello,

Do you want to add a subreport control on the main report at runtime? If yes then you can add subreport control at runtime by instantiating the subreport control in the main report. After instantiating you can add this control to the desired section of the report. For example:

DataDynamics.ActiveReports.SubReport mySub;
private void Customers_ReportStart(object sender, System.EventArgs eArgs)
{
   mySub = new DataDynamics.ActiveReports.SubReport();           
   this.Sections["Detail"].Controls.Add(mySub);
}


If I misunderstood the issue then I request you to provide more information about your requirements.

Regards,
Ankit Nigam

Re: Adding subreports at runtime?


03-09-2010, 9:54 AM
Ankit,
thanks for the reply.

shall i do the above in report start event or i can do it in section_format event also?

Re: Adding subreports at runtime?


03-09-2010, 11:25 AM
Hello,

If you are adding the controls at runtime, you would need to do that on the reportstart event.

Regards,
Prantik

Re: Adding subreports at runtime?


03-09-2010, 3:00 PM
can we add more than one subreport to one section? If yest how do i make sure that they dont overlap each other?

Re: Adding subreports at runtime?


03-09-2010, 10:45 PM
Hello,

You can add multiple subreport controls in a section but it my get extremely complicate depending on the number of subreports. You can also set there location in a section to avoid overlapping.

To know more about runtime reporting you may check this walkthrough.

You can also check this from thread in which similar issue had been discussed earlier.

Regards,
Ankit Nigam

Re: Adding subreports at runtime?


03-13-2010, 9:41 PM
I tried in a simple way, but the second sub report is covering the first one.

-----
mySub1 = New DataDynamics.ActiveReports.SubReport()
mySub1.Report = New TestARSrpt4411
Me.Sections("Detail").Controls.Add(mySub1)

mySub2 = New DataDynamics.ActiveReports.SubReport()
mySub2.Report = New TestARSrpt4422
Me.Sections("Detail").Controls.Add(mySub2)

-----

I guess I need to find a way to know the height of the sub reports and be able to set the top (in HTML sense) of succeding ones so that they donot cover each other.

Am I thinking in the right direction?
Can you point me to some resources/reference materials to implement this task?

Thanks.

Re: Adding subreports at runtime?


03-15-2010, 12:35 PM
Is it possible to change the position.y property of sub report at run time?

i am trying to acheive "multiple subreports in the same section at run time", but looks like it may not be possible using active reports, anyone?

Re: Adding subreports at runtime?


03-15-2010, 2:42 PM
Hello,

You can use the following code snippet to add two subreport controls in the detail section of the main report:

private void NewActiveReport1_ReportStart(object sender, EventArgs e)
        {
            mySub1 = new DataDynamics.ActiveReports.SubReport();
            mySub1.Name = "Sub1";
            mySub1.Size = new System.Drawing.Size(6, 1);         
            this.Sections["detail"].Controls.Add(mySub1);

            mySub2 = new DataDynamics.ActiveReports.SubReport();
            mySub2.Name = "Sub2";
            mySub2.Size = new System.Drawing.Size(6, 1);            
            this.Sections["detail"].Controls.Add(mySub2);
           
        }

private void detail_Format(object sender, EventArgs e)
        {
            NewActiveReport2 rpt1 = new NewActiveReport2();
            NewActiveReport3 rpt2 = new NewActiveReport3();
            mySub1.Report = rpt1;
            mySub2.Location = new PointF(0.0f, mySub1.Height);
            mySub2.Report = rpt2;       
        }


Regards,
Ankit Nigam

Re: Adding subreports at runtime?


03-16-2010, 8:10 AM
-----
mySub1.Size = new System.Drawing.Size(6, 1);

-----

Will that not restrict/limit the height of the sub report to a arbitrary number we chose?

what if the height needs to be more depending on the content?

Re: Adding subreports at runtime?


03-16-2010, 8:45 AM
Private Sub TestAR44_ReportStart(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ReportStart
mySub1 = New DataDynamics.ActiveReports.SubReport()
mySub1.Name = "Sub1"
mySub1.Size = New System.Drawing.Size(6, 1)
Me.Sections("Detail").Controls.Add(mySub1)

mySub2 = New DataDynamics.ActiveReports.SubReport()
mySub2.Name = "Sub2"
mySub2.Size = New System.Drawing.Size(6, 1)
Me.Sections("Detail").Controls.Add(mySub2)
End Sub

Private Sub Detail_Format(ByVal sender As Object, ByVal e As System.EventArgs) Handles Detail.Format
mySub1.Report = New TestARSrpt4411
mySub2.Location = New System.Drawing.PointF(0.0F, mySub1.Height)
Debug.WriteLine("sub1 height=" & mySub1.Height)
mySub2.Report = New TestARSrpt4422
End Sub

-------------------

this is what I am getting in Output window:

sub1 height=1

-------------------

Re: Adding subreports at runtime?


03-16-2010, 12:05 PM
Hello,

You can determine the height of the subreport control in the Section’s BeforePrint event. As I already informed you that it is quite complicated to adjust the multiple subreports in the same section at the run time, because you can only determine the height of subreport control in the before print event.

Regards,
Ankit Nigam