C# 按内容高度增长节报告的节
我试图在C# 按内容高度增长节报告的节,c#,vb.net,activereports,grapecity,C#,Vb.net,Activereports,Grapecity,我试图在ActiveReport的详细信息部分添加内容。但截面高度限制为2英寸。它只需要(2/0.2=)10项。我希望该部分随着内容的增加而增加其高度,以便它可以采用所有项目。似乎.CanGrow不起作用。我使用的代码如下 Dim lObjSecRpt As New GrapeCity.ActiveReports.SectionReport() Dim lObjLbl As New GrapeCity.ActiveReports.SectionReportModel.Label() Dim c
ActiveReport
的详细信息部分添加内容。但截面高度限制为2英寸。它只需要(2/0.2=)10项。我希望该部分随着内容的增加而增加其高度,以便它可以采用所有项目。似乎.CanGrow
不起作用。我使用的代码如下
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)
阿马尔
您试图在代码中做的是创建节并动态地向节添加控件。这就像在运行时创建报表布局一样。由于您只是将控件添加到detail部分,因此detail部分的format事件不会为每个控件触发,因为它没有绑定到任何数据。相反,您只是在向其添加控件。您可以检查并查看动态创建报告的示例
如果希望详图部分增长以显示所有添加的控件,则需要根据其内部控件的总高度增加其高度。例如,检查下面的示例代码,它演示了如何实现这一点。您只需将此代码添加到Form_Load事件中即可进行验证
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
我希望这能有所帮助。你能帮忙吗谢谢@Sankalp,你的答案对我很重要。但是作为一名程序员,有很多变通方法,我已经应用了最适合我的方法。但我担心的是“是否有
ActiveReport
提供的任何方法可以增加其内容的高度”。在我的例子中,位置和大小不是恒定的。一行中可能有多个控件,因此增加所有控件的高度不是一个好主意。