cancel
Showing results for 
Search instead for 
Did you mean: 

Alternate row colors (green bar) on group lines in Crystal Reports Server

Former Member
0 Kudos

I create a lot of drill-down reports and always want to show the data rows in alternate background colors. My drilldowns have at least two group levels. As everyone knows, it's easy to do alternate colors on detail rows and very (very) difficult with groups.

Here's what I came up with and want to share. My solution consists on one formula field that declares global variables (this should be placed in the report header section) and two different formula fields that will be placed on each of the group (header or footer) rows on the drill down.

The first formula field I've called ColorNum and contains this:

// ColorNum - place in the report header section

global numberVar colorNum;

global numberVar colorNum2;

colorNum := 0;

colorNum2 := 1;

You see, there's a global color variable for each group level in your report. Here I have two. Drag and drop this formula field into your report header section.

Now come the group level formula fields. The first one for the first group level:

// ColorFormula - place in the first group that you show.

// May be in header or footer - where ever you show your data

WhilePrintingRecords;

global numberVar colorNum;

if colorNum = 0 then

colorNum := 1

else

colorNum := 0;

colorNum;

Once you've placed the function there, go into the section expert's color tab and open the conditional code editor. Enter this:

WhilePrintingRecords;

global numberVar colorNum;

if colorNum = 0

then noColor

else color( 245, 245, 245);

The second formula field for the second group level:

// ColorFormula2 - place in the second group level that you show.

// May be in header or footer - where ever you show your data

WhilePrintingRecords;

global numberVar colorNum2;

colorNum2 := colorNum2 ;

if colorNum2 = 0 then

colorNum2 := 1

else

colorNum2 := 0;

colorNum2;

Now go to the conditional color code and enter this (looks familiar, no?):

WhilePrintingRecords;

global numberVar colorNum2;

if colorNum2 = 0

then noColor

else color( 245, 245, 245);

You see how this can be expanded to any number of groups by adding global variables and code sections.

By the way, in the ColorNum function, I set the colorNum2 variable to 1 and not 0 for a reason... try changing the value and see why.

Oh yes, don't forget to hide the fields that you've dropped onto your report.

I hope this helps!

- Russell

Edited by: Russell L Magidson on Sep 25, 2008 5:12 PM

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

I figure there can only be one of you. If this is the Russell I know, its Sharon, how are you?