Hey all,
Looking to do something here: I want to color a certain row in a listbox green, but only the row where the first element (column 0) matches a certain string called ydna(primary). To give a little background, I have a list of competitors in a race and want to only highlight YOUR player in green. The listbox has been populated already.
How do I cycle through the rows and only turn green the row with your racer’s name in it?
Mark: I think you’re close, but does that code go in CellBackgroundPaint, and does it check all 21 possible rows for the string? I’m getting “Out of Bounds” error right now.
Well, the trick here is that CellBackgroundPaint is called for ALL rows, even the empty ones.
So you need to restrict the painting to those which do have something in the row aka all the rows where the rowNumber “row” is smaller than the “number of rows” (which is the ListCount)
and then have this in the CellBackgroundPaint event
[code] if row < me.ListCount then
If Me.RowTag( row ) <> Nil Then
g.ForeColor = Me.RowTag( row ).ColorValue
g.FillRect(0, 0, g.Width, g.Height)
End If
end if[/code]
If you want to restrict the color to certain columns then just modify the code accordingly:
if row < me.ListCount then
if column = 1 then
If Me.RowTag( row ) <> Nil Then
g.ForeColor = Me.RowTag( row ).ColorValue
g.FillRect(0, 0, g.Width, g.Height)
End If
end if
end if