Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 409
  • Last Modified:

Background change in Crystal report

Hi

I have a report with 1 column. For example :

Heading1
wewewew
wewewew
wesd
sd
Heading2
sdsdf
sfdfv
Heading3
svdfvlkdfv
dbgb
gb
gb
fb
fbgtb
rbr
b
Heading4
ojkjfdg
elgjlg
kljfg

Now I want to color these in different colors like in different section:

In blue Color :
Heading1
wewewew
wewewew
wesd
sd

In Green Color :
Heading2
sdsdf
sfdfv

In Red Color :
Heading3
svdfvlkdfv
dbgb
gb
gb
fb
fbgtb
rbr
b

In black color
Heading4
ojkjfdg
elgjlg
kljfg


Thanks ..
0
sunilsagar
Asked:
sunilsagar
  • 6
  • 3
  • 2
2 Solutions
 
sunilsagarAuthor Commented:
Please help the string I could write.
0
 
peter57rCommented:
Are there always 4 headings ?

If not, what should happen if there are more than 4?
and what should happen if there are fewer than 4?

How is a 'heading' value different to any other value?  Are you using a grouping field to put similar values into the same group?
0
 
sunilsagarAuthor Commented:
There will be maximum 5 headings and there are chances that it would be less than 5.
All the values in the column are just list of values and they are all character data type.

No we are not grouping it, the data is already ordered and grouped (which is done at the database level)...what we see in Crystal Report is as values in single column.

I hope this makes things clearer.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
peter57rCommented:
SO how do you know which record is a 'heading'?

What if there are say only 2 'groups' - how do you decide which colours to use - is the first group ALWAYS Blue, the second Always Green and so on, or does the colour  depend on the 'heading' value?
0
 
sunilsagarAuthor Commented:
They are specific and distinct names like heading1 and heading2 , which never repeats.

And color will depend on the heading value. So Heading1 will be always blue and all the records will be blue until it reaches heading2 , and once heading2 is found, heading2 and all the  records below it will be green until it reaches to heading3 and so on ...  

Thanks
0
 
peter57rCommented:
You can do this using a couple of formula fields and a background formatting expression in the detail section.

I've just built this for 3 headings  - you can extend it as far as you wish...

Use a formula field like this - it must be added to the detail section..

whileprintingrecords;
stringvar lastone;
if {table.fieldName} in ["Heading1", "Heading2","Heading3"] then lastone :={table.fieldName};
""
In the report header add an initialisation formula field..

stringvar lastone:="xx";
""

Go to the [X+2] conditional format button for the background of the detail section and do..

stringvar lastone;
if lastone = "Heading1" then
crGreen
else if lastone = "Heading2" then
crRed
else if lastone ="Heading3"
then crYellow
else
crblue
0
 
sunilsagarAuthor Commented:
thank you so much peter57r, I will apply the same and will let you know.
0
 
mlmccCommented:
If that doesn't work please explain how the data structure.
Is each line above a single record or a field in a record?

mlmcc
0
 
sunilsagarAuthor Commented:
This didn't worked, actually .. it changed the background of Headings only not the records below the heading :(
0
 
mlmccCommented:
Add WhilePrintingrecords; as the first line in the formatting formula

mlmcc
0
 
sunilsagarAuthor Commented:
it worked. Thanks so much guys.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now