[quote=464208:@Rod Pascoe]
The trouble is it changes the whole listbox text colour each change rather than the current row and I’m tearing my hair out![/quote]
What Xojo IDE are you using? I don’t see this behavior in 2019r1.1 and API 1.0. Can you reproduce it in a sample project?
my list box shows text and background by month date and value 1,2 or 3 in first column
Textcolor:
Function CellTextPaint(g As Graphics, row As Integer, column As Integer, x as Integer, y as Integer) Handles CellTextPaint as Boolean
Dim m As Integer
Dim d As New date
If wahl=1 Then
rem Platz zeigen
If column > 0 Then
If row > 0 Then
If listbox2.cell(row,column)=“3” Then
g.ForeColor= Color.red
Else
If listbox2.cell(row,column)=“2” Then
g.ForeColor= Color.Orange
Else
g.ForeColor= Color.Green
End If
End If
Else
g.ForeColor= Color.Yellow
End If
Else
If listbox2.cell(row,column)=Str(jahr) Or listbox2.cell(row,column)=Str(jahr+1) Then
g.ForeColor= Color.red
End If
End If
Else
m=d.Month
If Val(lockedbefore.Text) < m Then // Bereich vor Datum geperrt
// Vergangenheit nicht mehr reservierbar/nderbar - Past no longer reservable / changeable
g.ForeColor= Color.White
Else
rem Platz/Monat zeigen nach Datum / Place / month show by date
If listbox2.cell(row,0)="3" Then
g.ForeColor= Color.Blue
Else
If listbox2.cell(row,0)="2" Then
g.ForeColor= Color.Orange
Else
g.ForeColor= Color.Green
End If
End If
End If
End If
End Function
Hintergrund Color:
Function CellBackgroundPaint(g As Graphics, row As Integer, column As Integer) Handles CellBackgroundPaint as Boolean
If row < Me.ListCount Then
If Me.cell(row, column ) ="WE" Then
g.ForeColor = &cAA0000
g.fillrect(0,0,g.Width,g.height)
End If
if row=lstClientTasks.listindex+1 then
if taskcolour="Black" then
g.DrawingColor=color.Black
end if
if taskcolour="Red" then
g.DrawingColor=color.Red
end if
end if
Not very elegant I know but wanted it plain to read for small brains like mine.
I also have a message box in my main loop that is filling the listbox so that the program stops with the message box saying what colour it should be.
This is what happens :-
The program runs, fills in the first line in the listbox in red text which is correct. It pops up a messagebox saying Red. So far so good.
I then click ok on the message box and the next line is filled in BUT not only is this line black (and the message box pops up to say it should be black too) but the red line above has now turned black too.
Am I being really really stupid? (quite possible!)
[quote=464303:@Rod Pascoe]he program runs, fills in the first line in the listbox in red text which is correct. It pops up a messagebox saying Red. So far so good.
I then click ok on the message box and the next line is filled in BUT not only is this line black (and the message box pops up to say it should be black too) but the red line above has now turned black too.
Am I being really really stupid? (quite possible!)[/quote]
Don’t use MsgBox to debug, it can be misleading like in this case. Because the MsgBox is closing, it asks the window to paint again, and your listbox, and since you’re using globals things being redrawn are changing color.
A simple and straightforward way to color the text of a cell is to store it’s color value as the CellTag.
Changed (row, column) to (row,0) so that the whole line was red and not just the first cell but other than that you saved what’s left of my hair!
Have 15 internet points on me please
[quote=464312:@Tim Parnell]Don’t use MsgBox to debug, it can be misleading like in this case. Because the MsgBox is closing, it asks the window to paint again, and your listbox, and since you’re using globals things being redrawn are changing color.
A simple and straightforward way to color the text of a cell is to store it’s color value as the CellTag.