cancel
Showing results for 
Search instead for 
Did you mean: 

Want robust solution for alternating row color, resetting every group

Former Member
0 Kudos

I would like a solution for displaying an alternating row color for my detail rows that resets every group, so that row 1 is always gray.

Our Crystal designer provided this code to me:

@rowcnt formula, suppressed, placed in Detail row:

Shared numbervar rowcnt;

rowcnt := rowcnt + 1;

@resetrowcnt, suppressed, placed in Group row:

Shared numbervar rowcnt;

rowcnt := 0;

Formatting formula, placed in Color in Detail > Section Expert:

Shared numbervar rowcnt;

if Remainder(rowcnt, 2) <> 0 then

color(241,241,241)

else

crWhite

This was working fine for me.

However, it is suddenly not working in one of my reports.

The report does happen to have two groups (rowcount.png).

When the report is run, all rows are colored (rowcount02.png).

This report was previously working fine!  I'm not sure what changed.

In any case... surely there must be standard code to do this very standard formatting.

I would be very grateful if someone could post some robust code to accomplish the following:

REPORT DATA IN DETAIL ROW, ALTERNATE ROW BANDING:

- Data in Detail row displays alternating row colors

- Odd rows are always shaded, even rows not

- Banding resets every group / does not continue pattern from previous group

REPORT DATA IN GROUP ROW, ALTERNATE ROW BANDING:

Some of our reports place row data in a group row (just the way it happened).

If you could also modify your code in this case.

Thank you!

Accepted Solutions (1)

Accepted Solutions (1)

former_member205840
Active Contributor
0 Kudos

Hi Vancouver,

-- Do you have any conditional suppress for detail section through Section Expert ? If so, you need to use the same condition for your accumulation formula.

-- Are you using 'rowcnt' variable name anywhere else in your report ? i.e. in any other formulas ?

Try to replace your formula with below formulas :

Reset formula :

Whileprintingrecords;

Numbervar cnt:=0;

row count Formula:

Whileprintingrecords;

Numbervar cnt:=cnt+1;

Detail section expert formula :

Whileprintingrecords;

Numbervar cnt;

if cnt mod 2 <> 0 Then Crred else crwhite

Thanks,

Sastry

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi, thanks for your responses.  Yes the following is in Suppress for the Detail section:

not(OnFirstRecord) and

{HedgeDetails.StrategyID}=previous({HedgeDetails.StrategyID}) and

{HedgeDetails.DealID}=previous({HedgeDetails.DealID})

Where should I be placing this same argument then? 

It's funny tho', this was all working fine a couple report versions ago, I have only been making cosmetic updates. 

Thank you for your counsel.  Unfortunately I cannot upload a report with data,

abhilash_kumar
Active Contributor
0 Kudos

The @rowcnt formula should be:


Shared numbervar rowcnt;

if {HedgeDetails.StrategyID} <> previous({HedgeDetails.StrategyID}) and

{HedgeDetails.DealID} <> previous({HedgeDetails.DealID}) then

(

     rowcnt := rowcnt + 1;

)

-Abhilash

Former Member
0 Kudos

Hi Abhilash/Sastry, since I'm going to switch to Sastry's formulas, could you please confirm correctness of the following. I can't actually run this report, I can only provide it to our London office, bit of a lag for testing.

@resetrowcnt:

Whileprintingrecords;

Numbervar cnt:=0;

@rowcnt:

Whileprintingrecords;

if {HedgeDetails.StrategyID} <> previous({HedgeDetails.StrategyID}) and

{HedgeDetails.DealID} <> previous({HedgeDetails.DealID}) then

(

     Numbervar cnt:=cnt+1;

)

Details section (Suppress):

not(OnFirstRecord) and

{HedgeDetails.StrategyID}=previous({HedgeDetails.StrategyID}) and

{HedgeDetails.DealID}=previous({HedgeDetails.DealID})

Please note: Suppress checkbox is selected AND the above formula is entered.

Details section (Color):

Whileprintingrecords;

Numbervar cnt;

if cnt mod 2 <> 0 Then color(241,241,241) else crwhite

abhilash_kumar
Active Contributor
0 Kudos

Looks good to me!

-Abhilash

abhilash_kumar
Active Contributor
0 Kudos

Hi,

What you've got in there is already a 'standard' way of doing this!

Like Sastry said, could you check if you've got conditional suppression logic for the details section?

Otherwise, would you be able to attach the report 'with saved data' for us to take a look at?

-Abhilash