On Apr 28, 2006, at 10:18 PM, Wade Little wrote:

I have a listbox that I populate with values from a DB. Before I do each query I get a boolean value which lets me know if the color of the cell background should be green or red.

The question is what is the easiest way to set the background color of the cell in the listbox based on boolean value, true is green and false is red.


I wrote this little switching routine and placed it in a Module (for general use)

------------

Option (condition as boolean, trueColor as color, optional falseColor as color = &cFFFFFF) as color

if condition then
        return trueColor
else
        return falseColor
end if


------------


When you want to change colors (background or otherwise) based on a boolean condition, try the following (in any graphics routine)

const Green = &c00FF00           'for readability
const Red = &cFF0000

g.foreColor = option ( conditionalExpression,   Green , Red )
g.fillRect (0, 0, g.width, g.height)

Put this in your CellBackgroundPaint event, and switch away!

BTW, you can overload this Options method to switch anything based on a boolean value (strings, integers, or other dataTypes) by declaring other Options methods each with a different parameter list in the method declaration....

Sort of a cheap "?(test, true, false)" from the C language. Consumes a few extra stack calls, but makes your code much more readable.....


Mark Levinson




_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to