On your first screen, looks like the top listbox has focus and the second listbox shows some cells in black/gray (very similar to my screenshot) but the first one in blue/white.
It seems that you have some code in Paint events and you may need to adjust that. If no code in Paint events, then the difference between Windows and Mac is more than I expected.
Is your issue about the focus, or rather about the selected row? I suspect it is the latter.
You didn’t answer whether you used the paint event. On a DesktopListBox there are actually three paint events, called PaintCellBackground, PaintCellText, and PaintDisclosureWidget, of which the first two are relevant for your issue.
If you use any of those two, I recommend to just let the system do it’s own thing for selected rows by adding this code near the top, before you did any drawing related to the issue:
If me.RowSelectedAt(row) Then Return False
If you don’t use those, the issue is likely with you Windows Theme. In that case,
just ignore it and tell the users to select a different theme
create and use your own theme in your app
or use defines to query whatever color is used for selected rows, calculate it’s brightness or other color properties in order to calculate a color with sufficient contrast, which you then can use in PaintCellText
Hi Stefan,
Yes, I have this code inside the PaintCellBackground event of both Listboxes.
g.DrawingColor = rgb(236,233,216)
If row >= Me.RowCount Then Return False
If Me.RowSelectedAt(row) Then
g.DrawingColor = Color.Blue
Else
g.DrawingColor = rgb(236,233,216)
End If
g.FillRectangle(0, 0, g.Width, g.Height)
If column = 0 Then // prima colonna
g.DrawingColor = Color.Blue
g.FillRectangle(0, 0, g.Width, g.Height)
Return True
End If
Once this was removed, everything returned to normal.
So, my question is:
How can I simply change the background and text of a row under a certain condition?
In this particular case, I’d like the text in the first column of a listbox to always be highlighted, choosing the text and background color myself.
Could you give me some guidance on what to write?
I am not sure what your screenshots above really depict. From the code in your latest post and it’s accompanying description I think you should mirror your code to the PaintCellText event, swap the colors from background to foreground colors and replace the FillRectangle calls with
g.DrawText(me.CellTextAt(row, column))
the idea being to set the foreground colors yourself, for those cells for which you painted the background yourself.
if so, the only thing missing is writing white text when the row is selected and the column is 0. If you need something else and you get stuck, let us know.