Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlight alternate rows 1

Status
Not open for further replies.

prakashroch

Technical User
May 2, 2002
21
US
i want to highlight the first item in the subgroup and then highlight the remaining items alternately. The number of records(items) in the subgroup keep changing. Here is how my group header 1 , group header 2 and detail section look like
H=Highlight

Brand (group header 1)
Subbrand (group header 2)
H--> item1 (detail section)
item1
H--> item1
item1
subbrand
H--> item1
item1
brand
subbrand
H--> item1
item1
H--> item1
subbrand
H--> item1

Here is the code that i lastly tried.

subbrand(group header 2 section) color formula:-
Global numberVar counter:=1;
crNoColor;


item(detail section) color formula:-
Local numberVar Flag;
numberVar counter;
if counter=1 then
(
crRed;
counter:=0
)
else crGreen

i am getting the first record in each subgroup black color no matter what color combinations i use. Since I am stuck with highlighting the first record I didn’t proceed further (alternate highlighting)
i guess it is trying to over write the red with green
any suggestion
thanks
 
you are sort of on the right track.

In the group2 (Subbrand) header place the following formula

@ReSetColorFlag (suppressed in Group 2 header)

whilePrintingRecords
numbervar colorflag := 1;

now in the detail section place the following formula

@IncrementColorFlag (suppressed in Details)

whilePrintingRecords
numbervar colorflag ;

colorflag := colorflag + 1;

Now...you can highlight a detail line 2 ways:

1. if you want the complete line highlighted...from margin to margin...then use the section expert color tab | conditional suppress the background color

2. if you want only a portion of a line highlighted then overlay that section with a blank text field...actually I usually give it a single space so there is something in there...then in the format editor for that field, conditional suppress the background color

in both cases the conditional suppress formula is the same

whileprintingrecords;
evaluateafter(@IncrementColorFlag);
numberVar colorflag;

if remainder(colorflag,2) = 0 then
crGreen
else
crRed;

that should do it Jim Broadbent
 
Thanks Jim
that was cool ....since i am new to CR i had no idea abt whileprintingrecords and evaluateafter functions
now i know how they work.....
so basically whileprintingrecords exceutes the code below it while printing the record
and evaluateafter will check for the change in the value of the varial or formula
i am correct???
is there any place where i could find the explanation on all the functions
thanks once again
Prakash
 
yes you have it right.

I always use "WhilePrintingRecords" in any formula...except in formulas used for grouping purposes or summary operations. The reason for this is that you are telling Crystal when to do the evaluation...not leaving it up to Crystal to decide for you.

EvaluateAfter() is only used when you are concerned about the value of a formula withing a given section...to force that formula to evaluate first.

they are basically described in the Crystal Helpfiles and again there is a good book for Crystal in general

The Complete Reference Crystal Reports 8.5 (other versions are available...by George Peck Jim Broadbent
 
Using whileprintingrecords in formulas often causes pass through SQL to fail when these whileprintingrecords formulas are referenced by the record selection criteria, so I suggest you only use it as required. If performance isn't a concern, or you're using Stored Procedures, then using them everywhere shouldn't do any harm.

Here's a CD reference for alternating colors every 5 rows, which is essentially the same as Jim's method:


The HELP file is pretty comprehensive, don't be shy about hitting F1.

And the CD site has lots of good stuff, here's the KB:


-k kai@informeddatadecisions.com
 
Of course you wouldn't use "WhilePrintingRecords" in a record select or Group select formula Jim Broadbent
 
Or any formula which is referenced by the record selection formula, this seems to break it too.

That being the point of:

"when these whileprintingrecords formulas are referenced by the record selection criteria,"

I never addressed using it in a record selection formula.

-k kai@informeddatadecisions.com
 
Thanks very much for the article. I get my rows now alternate color, but in reports where i have more than 1 page, the first two lines always comes up with the same background color.
Any ideas?
Thanks again
 
This effect is occuring based on placing your colour reset formula in the group header combined with the fact that you probably have repeated group headers on each new page.

Use "Not InRepeatedGroupHeader" in your colour resetting formula.

Naith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top