Listbox conditional colouring of rows

Hi everybody
I am trying to conditionally colour rows in a list box.
I have the only field in the list box set to ‘HasColour’ = true.
I have also added four long type fields to the queue directly after the field which I wish to colour and I am setting them in a routine.
Unfortunately I must be missing something because every row is coloured black (foreground and background).

Does anyone have any suggestions?

Hi Marc
This may help (7.7 KB)


1 Like

CW doesn’t have a feature to color an entire row (apart from the selected row)

There are two common ways to color a cell

The original way is to use PROPList:Color
(which appears as an asterisk * in the format string)
The data column is then followed by 4 Longs in the queue
Each directly holds a color value, ex: color:red


This approach is perfect for situations where the user might be selecting any possible color

The other way is to use PROPList:Style
(which appears as a Y in the format string)
(styles were new around C5 or so)
A style lets you control many things not just color (for instance font)
Each style value (1,2,3…) is predefined to have a set of attributes

InitStyles ROUTINE
CurrStyle LONG,AUTO 
 CurrStyle = LocalCellStyles::Qty_Zero
 ?list{PROPSTYLE:TextColor   ,CurrStyle} = COLOR:Red
 ?list{PROPSTYLE:TextSelected,CurrStyle} = COLOR:White
 ?list{PROPSTYLE:BackSelected,CurrStyle} = ?list{PROPSTYLE:TextColor,CurrStyle}
 ?list{PROPSTYLE:FontStyle   ,CurrStyle} = FONT:Bold
 CurrStyle = LocalCellStyles::Qty_Greater
 ?list{PROPSTYLE:TextColor   ,CurrStyle} = COLOR:Blue
 ?list{PROPSTYLE:TextSelected,CurrStyle} = COLOR:White
 ?list{PROPSTYLE:BackSelected,CurrStyle} = ?list{PROPSTYLE:TextColor,CurrStyle}
 ?list{PROPSTYLE:FontStyle   ,CurrStyle} = FONT:Bold

Then in YourBrowse.SetQueue set values the style field in the queue to be a value a like LocalCellStyles::Qty_Zero

Q              QUEUE
WAL_QTY:Style    LONG        
                 ! and a few other fields

MyBrowse.SetQueue PROCEDURE
  Q.Wal_Qty = WAL:Qty
  IF WAL:QTY = 0    ! <---  simplified from my real code.
       Q.WAL_QTY:Style = LocalCellStyles:Qty_Zero
  ELSE Q.WAL_Qty:Style = LocalCellStyles:Qty_Greater

As you can see I prefer to create equates for the values
otherwise the code is difficult to follow
I mean what does Q.WAL_Qty:Style = 6 represent?

LocalCellStyles        ITEMIZE,PRE(LocalCellStyles:)
Qty_Zero                       EQUATE(1)
Qty_One                        EQUATE
Qty_Greater                    EQUATE
Qty_Greater_Rect               EQUATE
Sheet_WithPath                 EQUATE
Sheet_WithOutPath              EQUATE

There is another way to set a color, but I have to confess that I don’t use it
you can use PROPList:ColStyle to set the style for an entire column
(which appears as Z(n) in the prop:format where n is a style number)
I dimly recall there is some trick to getting it to work.
Like you need to have a cell style somewhere else in the list as well, or something like that.