Pages

Wednesday, May 13, 2009

Crystal Report with Alternate Row Color


In my previous post, I walked you through creating a simple crystal report in visual studio. I also mentioned that in the following posts, I will touch upon different topics relating to crystal report. Creating a crystal report is easy; however the users always expect better looking reports for their use.

One of the questions which pops up on many forums is ‘how to have alternate row color’ in a crystal report just like a gridview in asp.net. To have alternate row color in a crystal report, you have to format a section. A section is separated by a gray bar on the report. There are different sections in a report including ReportHeader, PageHeader, GroupHeader, Details and ReportFooter sections. Usually records appear under the Details Section. To have alternate row color, follow these steps:


1. Right click on Details Section and select Section Expert…



2. In the Section Exert panel, select the Color Tab and click on the formula icon (with x+2 written on it).



3. In the Formula Section panel, we have to write code to change the color for alternate rows.



4. Enter the following code as in listing 1 and click on Save and close icon at the top.

Listing 1


IF RecordNumber mod 2 = 0 Then
crRed
Else
NoColor


Now when you view the report, you will see alternate rows with a red background. That is all required to have the required alternate coloring effect. Hope this post was useful for you. Stay tuned for more…

1 comment: