Example 1: creating a gray bar effect

The following DataWindow object shows alternate rows with a light gray bar. The gray bars make it easier to track data values across the row.

Figure 23-6: Displaying alternate rows in gray bars for data highlighting

The sample is titled Employee Report and shows five rows of grouped data for the department having the I D of 100. Every other row is highligted with a dark background to make the data easier to track across the rows.

To create the gray bar effect:

  1. Add a rectangle control to the detail band and size it so that it surrounds the controls you want highlighted.

    To make sure that you have selected the detail band, select the Position tab in the Properties view and select Band from the Layer drop-down list.

  2. To make it easier to see what you are doing in the Design view, select the General tab and set the Brush Color to White and the Pen Color to Black. A narrow black line bounds the rectangle.

  3. Select Send to Back from the rectangle’s pop-up menu.

  4. To hide the border of the rectangle, set the Pen Style to No Visible Line.

  5. Click the button next to the Brush Color property on the General page.

  6. In the Modify Expression dialog box, enter the following expression for the Brush.Color property:

    If(mod(getrow(),2 )=1, rgb(255, 255, 255 ), rgb(240, 240, 240 ))
    

    The mod function takes the row number (getrow()), divides it by 2, then returns the remainder. The remainder can be either 0 or 1. If the row number is odd, mod returns 1; if the row number is even, mod returns 0. The boolean expression mod(getrow(),2)=1 distinguishes odd rows from even rows.

    The rgb function specifies maximum amounts of red, green, and blue: rgb (255, 255, 255). Specifying 255 for red, green, and blue results in the color white. If the row number is odd (the condition evaluates as true), the rectangle displays as white. If the row number is even (the condition evaluates as false), the rectangle displays as light gray (rgb (240, 240, 240)).