Color on Any array browse

This forum is for eXpress++ general support.
Post Reply
Message
Author
omni
Posts: 567
Joined: Thu Jan 28, 2010 9:34 am

Color on Any array browse

#1 Post by omni »

Roger,

We do a lot of row column colors based on field, so red if a certain field is not a *, stuff like that.
We have one dcbrowse that uses an array of fields to build the browse and then uses ELEMENT 1, ELEMENT 2, ETC for the browse, allowing users to sort based on an element.
they now want to use our red row color if two fields are specific, but cannot figure out how to do that with Elements.

The normal color command is similar to this

COLOR {|aColor|aColor := IIF( TRACTOR->PPLOAD<>0 .and. TRACTOR->TRCDISP<>"*" , ;
{ GRA_CLR_RED,GRA_CLR_WHITE }, ;
{ GRA_CLR_BLACK,GRA_CLR_WHITE } ), ;
aColor }

The array uses
aRecords := {}
AAdd(aRecords,{Tractor->asgnarea, ;
etc


In this case those two fields are Element 19 and Element 20.



Fred
Omni

Wolfgang Ciriack
Posts: 497
Joined: Wed Jan 27, 2010 10:25 pm
Location: Berlin Germany

Re: Color on Any array browse

#2 Post by Wolfgang Ciriack »

Use DC_GetColArray(19, oBrowse) or. DC_GetColArray(20, oBrowse) in your COLOR codeblock.
_______________________
Best Regards
Wolfgang

User avatar
Tom
Posts: 1309
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Color on Any array browse

#3 Post by Tom »

In addition to Wolfgang's reply:

In DCBROWSECOL, the first parameter given to the color codeblock is the contens of the cell. So, if you have an array that has the values "a", "b" or "c" in any column, you can do something like this:

Code: Select all

LOCAL aColors := {{GRA_CLR_GREEN,GRA_CLR_BLACK},{GRA_CLR_RED,GRA_CLR_BLACK},{GRA_CLR_BLUE,GRA_CLR_BLACK}}

...

DCBROWSECOL ELEMENT <n> ... COLOR {|x|aColors[IF(x="a",1,IF(x="b",2,3))]}
which will colorize the cell with the first color pair (green) in "aColors" if the value is "a", with the second (red) if it's "b" and with the third (blue) otherwise. To be honest, it would be a little more elegant to use an UDF there. Anyway, this works with arrays and tables, since the color codeblock gets the value shown in the cell.

Besides, your color codeblock code is a little confusing. You create the color array there. Don't do that. Create it somewhere else (as a LOCAL var) and just return the elements needed, as shown in my code above.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
Tom
Posts: 1309
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Color on Any array browse

#4 Post by Tom »

This would be it with Wolfgang's suggestion. It may raise an error with an empty array since DC_GetColArray() always returns an empty string as the default.

Code: Select all

LOCAL aColor := {{{ GRA_CLR_RED,GRA_CLR_WHITE },{ GRA_CLR_BLACK,GRA_CLR_WHITE }}

....

DCBROWSE oBrowse DATA aRecords ....

DCBROWSECOL ELEMENT x PARENT oBrowse WIDTH 20 .... COLOR {||aColors[IF(DC_GetColArray(19,oBrowse)#0.AND.DC_GetColArray(20,oBrowse)#"*",1,2]}
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

omni
Posts: 567
Joined: Thu Jan 28, 2010 9:34 am

Re: Color on Any array browse

#5 Post by omni »

Hi thanks for all the responses.

trying to colorize the row, not the cell itself. Color is based on what is in one of the cells.

Fred

User avatar
Tom
Posts: 1309
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Color on Any array browse

#6 Post by Tom »

Put the color codeblock in a var and use it with every column.

There is no such thing as a row object. Browses are composed from column( object)s, and columns are three cellgroup( object)s, one for the heading, one for the data area and one for the footing. The columns don't know each other.

Code: Select all

LOCAL aColor := {{{ GRA_CLR_RED,GRA_CLR_WHITE },{ GRA_CLR_BLACK,GRA_CLR_WHITE }}, bColor := {||aColors[IF(DC_GetColArray(19,oBrowse)#0.AND.DC_GetColArray(20,oBrowse)#"*",1,2]}

....

DCBROWSE oBrowse DATA aRecords ....

DCBROWSECOL ELEMENT x PARENT oBrowse WIDTH 20 .... COLOR bColor
DCBROWSECOL ELEMENT y PARENT oBrowse WIDTH 20 .... COLOR bColor
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

Post Reply