Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

2.09 Fields That Can Grow

Fields that Can Grow

When working with database fields, it’s common to show fields that display a large amount of data. For example, an inventory table can have a Description field that stores a lot of data. Depending upon the inventory item, some descriptions will be short and other will be long. When you add the Description field to the report, you want to make it tall enough to display multiple lines of information, but this will leave a lot of empty space when the descriptions are short. The way to solve this problem is to make the field only one line tall and enable the Can Grow option. The Can Grow option lets the field expand to as many lines as necessary so that the full field is displayed. The Can Grow option is located on the Common tab of the Format Editor.

Fields can only grow taller. They won’t grow wider.

The next two figures illustrate printing a person’s first and last name as well as some notes about the person. The first figure shows the fields in the Design window. Notice that the Notes field is only one line tall. Although you can’t see it here, the Can Grow option has been enabled for the Notes field. The second figure shows the preview of the report. Notice that the Notes field changes size based upon how much data it has to display.



Figure 2-17. A Can Grow text object in design mode.


Figure 2-18. The text object displaying multiple lines of text.

Sometimes there can be so much data in a field that displaying it causes the report to look unusual and could even span over multiple pages. As a precaution to make sure the field doesn’t grow too large, there is a property to set the maximum number of lines. It is also on the Common tab of the Format Editor dialog box and is located next to the Can Grow checkbox. By default, the number of lines is set to zero which effectively disables the option and there is no limit. If you want to set a limit, override the zero with the maximum number of lines. The field height will not exceed the number specified.

One thing to be aware of, is that if another field is located below a field that has the Can Grow option enabled, it’s possible that the top field will expand over the field below it and overwrite it. There are two ways to prevent this. The first way is to make sure that no fields are close enough to the Can Grow field that they might be overwritten. This isn’t a very practical solution because it requires leaving a lot of blank space between the fields. The second option is to put the Can Grow field at the bottom of the section, so as the field grows the section enlarges to compensate for the extra lines needed. The data in one section won’t overwrite the data in the next section. If it isn’t practical to put the Can Grow field at the bottom of the section, insert another section below the current section and put the extra fields in the second section. This trick is discussed in Chapter 8.

One final feature of the text object is that you can import an external text file into it. Double-click on the text object to go into edit mode. Then right-click on it and select Insert from File. This opens the File Open dialog box that lets you select the text file. The file’s content gets inserted into the text object at the cursor location.

Special Formatting

There are two types of data that have their own formatting built-in: Rich Text Format (RTF) and HTML. Crystal Reports supports displaying both types of data. The rule is that the object must be a string or memo field or formula. If these conditions are met, when you go to the Format Editor and look at the Paragraph tab, a new item is listed: Text Interpretation. This is a drop-down box that lets you select if the field should be displayed as an RTF field or as HTML. If you select either one of these items then Crystal Reports will convert the text to match the expected output.