Modifying the Report Object Properties
The Area class and Section class have similar properties to each other. You can enable or disable formatting properties such as suppressing the object, keeping the object on the same page, and printing it at the bottom of the page. The difference between the two is that every section has to be within an area. Any formatting done to the area will affect all the sections within the area. But formatting done to a section will not affect the area it is in. Nor will other sections in the area be affected.
The ReportObject class is the base class for the objects that are used in a report. It has some of the basic formatting options that are common to all objects. For example, there are properties in the class for changing the objects positioning on the report. You can modify the Top and Left properties as well as the Left and Width properties. You can also modify the object’s border using the Border property and its various Enable related options (Suppress, KeepTogether, etc.) using the ObjectFormat property.
To modify the properties that are unique to an individual report object, the object variable must be declared as the proper data type. For example, declaring an object variable of the type LineObject lets you modify the LineThickness property. Assign the report object to the variable by explicitly casting it as the proper data type. The next few examples demonstrate modifying different objects on a report.
Dim myReport As New CrystalReport1()
Dim mySection As CrystalDecisions.CrystalReports.Engine.Section
mySection = myReport.ReportDefinition.Sections.Item("ReportFooter")
mySection.SectionFormat.EnableKeepTogether = True
Dim myReport As New CrystalReport1()
CrystalReportViewer1.ReportSource = MyReport
Dim myReport As New CrystalReport1()
CrystalReportViewer1.ReportSource = MyReport
The TextObject lets you modify the content that an object displays on the report. It has a Text property that sets what is displayed. Simply assign a string to it to change its contents.
Dim myReport As New CrystalReport1()
Dim myText As CrystalDecisions.CrystalReports.Engine.TextObject
myText = CType(myReport.ReportDefinition.ReportObjects.Item("HeaderText"), _
CrystalDecisions.CrystalReports.Engine.TextObject)
myText.Text = "New Report Header"
CrystalReportViewer1.ReportSource = MyReport
The FieldObject object is used to print fields from a data source. You can’t modify it. The DataSource property is a FieldDefinition class and this is where the content is stored. Unfortunately, it is a read-only property and you aren’t allowed to modify it. This applies to database fields, running totals, summary fields, etc. The only way to modify these fields is to base them off of a formula and modify that formula during runtime. This is discussed in Chapter 16.