Customizing a Report


If you look closely at Figure 25-17, you can probably think of several ideas for improving the report. Although the StudentId field groups records, it is probably not the value that you would use to locate a student’s records. It would be more convenient to display the students’ names instead.

The StudentId, LastName, and FirstName fields are repeated for every detail row, even though they are the same for each StudentId group.

The report also has some basic arrangement problems. The date field in the upper-left corner is also too small to show the entire date. Each student’s average test score is shown, but the label to the left is the student’s ID, not something meaningful. The average would also look better aligned below the students’ scores. Finally, the columns are a lot wider than they probably need to be, making it hard to read the whole report.

Fortunately, it’s relatively easy to customize the report. The basic idea is similar to using the Visual Studio development environment to customize a form. The Toolbox provides tools that you can place on the report just as you place controls on a form. When you select an object on the report, you can view and modify the object’s properties in the Properties window.

Although the basic idea is the same, some of the details are different. For example, you cannot change a Text Object’s text in the Properties window. Instead you need to right-click the object, select the Edit Text Object command, and enter the new text on the report.

Other properties have names that differ from those used by Visual Basic. For example, the HorAlignment property determines the object’s horizontal alignment instead of the Visual Basic Alignment property, the Width and Height properties determine the object’s size instead of the Visual Basic Size property, and the TextColor property determines the field’s color instead of the Visual Basic ForeColor property.

The details are different, but the ideas should be familiar to you, and you should be able to achieve the effects you want with a little experimentation.

To make this example easier to read, start by opening the report in the development environment. Click the Print Date field in the page header and use its drag handles to make the field wide enough to display the full date.

To change the text displayed by the first group from StudentId to the students’ names, right-click the Group Header #1 bar at the top of the first group and select the Group Expert command to display the Group Expert dialog box shown in Figure 25-18.

image from book
Figure 25-18: Use the Group Expert to add, remove, and rearrange groups

Select the Students.StudentId field in the list on the right and click the Options button to see the dialog shown in Figure 25-19.

image from book
Figure 25-19: Use the Change Group Options command to modify a group’s properties.

Select the Options tab and select the Customize Group Name Field check box. Select the Use a Formula as Group Name option. Next click the X+2 button to the option button’s right to display the Formula Workshop shown in Figure 25-20.

image from book
Figure 25-20: The Formula Workshop helps you define formulas for the report.

From the Formula Workshop’s field tree (the second tree from the left with the LastName field highlighted), drag the Students.FirstName and Students.LastName fields into the text box at the bottom. Add text to concatenate a space between the two fields as shown in Figure 25-20.

When you are finished, click the Save and close button at the upper left. Then close the Change Group Options dialog box and the Group Expert. Now, when you run the report, this group’s name includes the students’ names. This value is displayed both in the group’s header for each student and in the group tree display on the left of the CrystalReportViewer control.

Select the Group #1 Name field in the group’s header, and use its grab handles to make it wide enough to display a reasonably long name.

Because the group header displays the students’ first and last names, the report doesn’t need them in the details section. Select those fields and delete them.

To prevent each student’s test scores from appearing in a separate visible group, right-click the Group Header #2 and select the Suppress (No Drill-Down) command. Then delete the Group #2 Name field from this section and resize the section to make it as short as possible. Similarly, remove the Group #2 Name field from the Group Footer #2 section and make that section as short as possible.

Next, remove the Group #1 Name field from the Group Footer #1 section. Then use the Toolbox to add a new Text Object to that section and set its text to Average. Place it to the left of the existing Scores.Score control.

In the Report Footer section, right-click the Grand Total field, select Edit Text Object, and change the control’s text to Class Average. Finally, drag the StudentId field from the Details section to the Group Header #1 section and drag all of the fields into more pleasing locations.

Figure 25-21 shows the rearranged report.

image from book
Figure 25-21: The rearranged report is much easier to read.




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net