Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

2.09 Using the Report Options

Using the Report Objects

A report is very similar to a Windows form. Just like a form, the report is listed as a separate object under your project in the Solution Explorer window, there are various controls that can be added, and it is a class that has to be instantiated before using it. The objects that are added to a report are also similar to the ones you use when building forms. This section describes the different objects and how they are used. It also gives you a reference for the properties of each object. Every property isn’t listed because that would require reprinting the MSDN documentation. But the properties you’ll need to use on a regular basis are highlighted here.

There are three controls in the report toolbox (see Figure 2-16). You can access these and many others by right-clicking on the report and selecting the Insert menu option (see Figure 2-17).



Figure 2-16. The control Toolbox.


Figure 2-17. The Insert menu option.

Adding, Resizing and Moving Report Objects

The objects on a report work the same as the controls on a form. The objects that are listed in the toolbox can be added to the report by dragging and dropping them onto the proper section of the report. You can also double-click on them and they will be automatically added to the section that has the focus (its header bar will be blue while the other header bars will be gray). If you have an existing control that you want to reuse and it has already been formatted, then you can highlight it and copy and paste it. This creates a copy that is attached to your pointer and will move around as you move your mouse. When you have it positioned properly, click the mouse button to drop it there. You can also select multiple objects for copy and paste.

Selecting multiple objects is done by holding down the control or shift key and clicking on the individual controls. You can also draw a temporary window on the report and any controls that are included in the window get selected. Do this by holding down the mouse button and moving the mouse to enlarge the box. Let go of the mouse when the box is complete and the objects will be selected.

There is a strange behavior to be aware of when selecting multiple objects using the window technique. You can’t draw a window if another object is already selected. You have to first click anywhere on the report to unselect the current object and then you can draw the box. For example, assume that you selected a textbox object. You then decide that you really wanted to select multiple textboxes so you click elsewhere on the report and attempt to draw a window. Unfortunately, nothing will happen. It only results in the textbox getting unselected. You need to click the mouse again to start drawing the window.

You can only select multiple objects when they are compatible. For example, the box and line objects can be selected together, but the box object can’t be selected with the text object.

Resizing a control is done by selecting it to give it the focus. Position the mouse over the sizing handles on any side and drag them. When resizing multiple objects, the sizing handle will only appear on the last control selected. As you resize the last control, its new size changes as you move your mouse. The other controls will not change until you release the mouse button. An option for resizing objects is to let Crystal adjust their size to be the same for each one. After selecting all the objects, right-click on one and select the Size menu option. From there you can choose Same Width, Same Height, or Same Size.

When moving objects on the report, it can be helpful to display the grid lines. This makes it easier to line up objects with each other. You have the option of making the objects snap to the grid lines. This means that when you move a control, its edge must be placed on a grid line. It can’t be placed between grid lines. When you release the mouse, the object will automatically snap to the nearest grid line. Turning grid lines feature and the snap-to feature on and off is controlled by changing the designer properties. Right click on the report and select Designer/Default Settings.

Turning on the snap-to grid lines option can be a blessing or a curse. There are two problems that can occur when this option is turned on, and they both seem to occur most frequently with reports that have been created with the report experts. The first problem is that when the report expert creates a report, it doesn’t always place the controls on the grid lines. When you later want to rearrange the controls on the report, or add more controls, you can’t get the new objects to line up because they are snapping to the grid lines. Since the wizard placed the objects between grid lines, they won’t line up properly when they are on the grid lines. The second problem with using the snap-to grid lines option is that it can be impossible to move multiple objects and keep their spacing consistent. I call this the “rubber band effect”. As you drag the objects across the report, some will move and others won’t. But as you move your mouse further, the ones that haven’t moved will now seem to snap into place and catch up with the other objects. If you move your mouse fairly quickly across the page they will appear to bounce around like they are being pulled by rubber bands. Unfortunately, you have no control over this and sometimes it can be impossible to make all the objects line up as you expected.

An easy way to align multiple objects is to use the Align menu option. After selecting the objects, right-click on one of them and select Align. The options to choose from are Tops, Middles, Bottoms, Baseline, Lefts, Centers, Rights, and ToGrid. Each of these options aligns multiple objects to a single object. The object that is used as the basis for alignment is the last object selected. You can identify the last object selected by seeing which one has the sizing handles on it.