Grow a Section of Section report by the content height

1.6k views Asked by At

I am trying to add content in the detail section of ActiveReport. But the section height is limited to 2 inches. It is taking only (2/0.2 = )10 items. I want the section to increase its height as the contents increase, so that it can adopt all item. It seems like .CanGrow is not working. The code I am using is as below.

Dim lObjSecRpt As New GrapeCity.ActiveReports.SectionReport()
Dim lObjLbl As New GrapeCity.ActiveReports.SectionReportModel.Label()
Dim c As Single = 0.2F

Try

lObjSecRpt.Sections.InsertPageHF()
lObjSecRpt.Sections(0).BackColor = Color.WhiteSmoke
lObjSecRpt.Sections(0).Height = 0.0F

lObjSecRpt.Sections.Insert(1, New GrapeCity.ActiveReports.SectionReportModel.Detail())
lObjSecRpt.Sections(1).BackColor = Color.WhiteSmoke
lObjSecRpt.Sections(1).CanGrow = True

For Each dr As DataRow In mObjDtReport.Rows
    lObjLbl = New GrapeCity.ActiveReports.SectionReportModel.Label()

    lObjLbl.Alignment = GrapeCity.ActiveReports.Document.Section.TextAlignment.Left
    lObjLbl.Font = New System.Drawing.Font("Arial", 10, FontStyle.Regular)
    lObjLbl.Location = New PointF(0.0F, c)
    lObjLbl.Height = 0.2F
    lObjLbl.Width = 1.0F
    lObjLbl.Text = CStr(dr("RptObjNam"))
    lObjSecRpt.Sections(1).Controls.Add(lObjLbl)
    c += c
Next

Me.rptViewer.LoadDocument(lObjSecRpt)
1

There are 1 answers

1
Sankalp1984 On BEST ANSWER

Ammar,

What you are trying to do in the code is creating sections and adding controls to the sections on the fly. So this is like creating a report layout at runtime. Since you are simply adding controls to the detail section, the format event for the detail section will not fire for each control as it is not bound to any data. Rather you are just adding controls to it. You can check and example of creating reports on the fly here.

If you want that the detail section should grow to show all the added controls, then you will need to increment its height on the basis of the total height of the controls inside it. For example check the sample code below which demonstrates how this can be done. You can simply add this code to the Form_Load event to verify it.

    Dim lObjLbl As New GrapeCity.ActiveReports.SectionReportModel.Label()
Dim c As Single = 0.2F
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Dim rpt As New GrapeCity.ActiveReports.SectionReport
    rpt.Sections.InsertPageHF()
    rpt.Sections(0).BackColor = Color.Yellow
    rpt.Sections(0).Height = 1.0F
    rpt.Sections.Insert(1, New GrapeCity.ActiveReports.SectionReportModel.Detail())
    rpt.Sections(1).Name = "Detail"
    rpt.Sections("Detail").BackColor = Color.Gainsboro
    rpt.Sections("Detail").CanGrow = True

    Dim i As Integer
    For i = 0 To 20
        Dim lObjLbl As New GrapeCity.ActiveReports.SectionReportModel.Label()
        lObjLbl.Alignment = GrapeCity.ActiveReports.Document.Section.TextAlignment.Left
        lObjLbl.Font = New System.Drawing.Font("Arial", 10, FontStyle.Regular)
        lObjLbl.Location = New PointF(0.0F, c)
        lObjLbl.Size = New SizeF(1.0F, 0.2F)
        lObjLbl.Text = "Record: " + i.ToString()
        lObjLbl.BackColor = Color.Aqua
        rpt.Sections("Detail").Controls.Add(lObjLbl)
        c += 0.2
    Next
    Dim height As Double = 0
    For Each control As GrapeCity.ActiveReports.SectionReportModel.ARControl In rpt.Sections("Detail").Controls
        height = height + control.Height
    Next
    rpt.Sections("Detail").Height = height
    Viewer1.LoadDocument(rpt)
End Sub

I hope this helps.