Page 1 of 1
Color on Any array browse
Posted: Thu Dec 04, 2025 11:23 am
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
Re: Color on Any array browse
Posted: Thu Dec 04, 2025 10:53 pm
by Wolfgang Ciriack
Use DC_GetColArray(19, oBrowse) or. DC_GetColArray(20, oBrowse) in your COLOR codeblock.
Re: Color on Any array browse
Posted: Fri Dec 05, 2025 1:12 am
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.
Re: Color on Any array browse
Posted: Fri Dec 05, 2025 4:21 am
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]}
Re: Color on Any array browse
Posted: Fri Dec 05, 2025 7:44 am
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
Re: Color on Any array browse
Posted: Fri Dec 05, 2025 9:25 am
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