field colors in list view

Hi

I’m sure I’m missing something obvious, but how do you set the color of the fields in list view dynamically. For example, if I have a column for profit/loss I want to show the figure in a row as green if it’s a profit and red if it’s a loss. I can use a colored image as Graham pointed out in another post, but how do I affect the attributes of a field dynamically?

Thanks

Sham

Basically you will just loop through the records and then set the element color (can’t remember if it is foreground or background color you want to set but assuming foreground). So if the field/column you want to dynamically change is called ‘profit’ (and you have also given it that element name) you’d do something like:

for ( var i = 0 ; i < controller.getMaxRecordIndex() ; i++ )
{
    if ( profit < 0 )
    {
        elements.profit.fgcolor = '#ff0033'
    }
    else
    {
        elements.profit.fgcolor = '#009933'
    }
}

Thanks John. If I use ‘element.’ to change the color of an element, it changes it on every row in list view, rather than just the single row I’ve selected. I can sort of understand this because it’s the same as changing the properties of the form in designer mode and when you do that it applies to all instances of that form. Robert suggested using HTML so I’m going to try that.

Hello

I think the easy way to do that is to create a text calculation field to display in place of your field. You shoud return something like this from you calculation field :

if (profit > 0)
{
return ‘ ’ + profit + ‘’;
}
else
{
return profit;
}

Don’t forget to set the “Display type” property of new field to “HTML_area”.

I hope it help you.

:wink:

DomTom.