I have an issue with PaintCellText that I cannot resolve. I am attempting to change the color of text in a DeskTopListBox cell if certain conditions are met (i.e., if the value to be displayed in the cell is > 2). I’ve gone through the documentation several times and scoured the online resources but the problem continues and I know that I’m missing something obvious.
My confusion is aggravated by the fact that what I’m trying to accomplish is similar (but not identical) to code that I’ve already included in another listbox that is part of the same application - although in that case I change the color of the text for an entire column, not just the color of the text in an individual cell.
I have stepped through the code and seen that the color change does, in fact, occur when the condition is satisfied, but reverts to Black when the next cell in the table is populated. I’ve tried using a Return of both True and False (as well as not specifying the Return, as shown in the code examples below) but the problem continues.
In addition to the PaintCellText Event, the other Events applicable to the offending ListBox are:
CellPressed
DoublePressed
Opening
PaintCellBackground
PaintHeaderContent
RowComparison
Since 2 of the other Events defined for the ListBox involve graphic functions, I’m wondering whether my CellTextPaint code is being over-written by some other Event that contains a graphic operation.
Here’s the CellTextPaint code from the ListBox control (ListBoxInvoices) that correctly colors all the text in specific columns:
If column = 0 Then
g.ForeColor = &c0000FF10
ElseIf column = 4 Then
g.ForeColor = &cFF000000
End If
The result is exactly what I wanted to achieve for those columns.
The CellTextPaint code from the ListBox control (ListBoxCases) that is causing me heartburn:
If column = 10 AND nPaperWork > 2 Then
g.Bold = True
g.ForeColor = &cFF000000
End If
The “nPaperWork” variable is defined as a Property for the window (wMain) and the value is set in the method (OpenCases) that populates the listbox (ListBoxCases). The value of nPaperWork (and the value displayed in the listbox) in Column 10 is “3”.
The application initially applies a Red color to the value in Column 10 (“3”), but immediately re-draws the text using a Black color.
Again, I think I’m missing something fairly obvious, so I would appreciate any suggestions.
Thanks in advance.