Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

15.05 Modifying the Report Object Properties

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.

Listing 15-7. Modify properties of the ReportFooter section.
Dim myReport As New CrystalReport1()
Dim mySection As CrystalDecisions.CrystalReports.Engine.Section
mySection = myReport.ReportDefinition.Sections.Item("ReportFooter")
mySection.SectionFormat.EnableKeepTogether = True
mySection.SectionFormat.EnableSuppress = False
CrystalReportViewer1.ReportSource = MyReport
Listing 15-8. Modify the border of the report object State using the ReportObject data type.
Dim myReport As New CrystalReport1()
Dim myObject As CrystalDecisions.CrystalReports.Engine.ReportObject
myObject = myReport.ReportDefinition.ReportObjects.Item(“State”)
myObject.Border.TopLineStyle = CrystalDecisions.[Shared].LineStyle.SingleLine
myObject.Border.BottomLineStyle = CrystalDecisions.[Shared].LineStyle.DoubleLine
CrystalReportViewer1.ReportSource = MyReport
Listing 15-9. Modify the line properties of the object Line using the object’s specific data type.
Dim myReport As New CrystalReport1()
Dim myLine As CrystalDecisions.CrystalReports.Engine.LineObject
myLine = CType(myReport.ReportDefinition.ReportObjects.Item(“Line1”), _
CrystalDecisions.CrystalReports.Engine.LineObject)
myLine.LineStyle = CrystalDecisions.[Shared].LineStyle.DashLine
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.

Listing 15-10. Modify the Text property of a TextObject located in ReportHeader.
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.