I’m once again stumped by the sequence of when events occur.
I have a listbox showing suspense items (a task list). If a task is overdue I want it to display the text in red. When I run a trace the CellTextPaint event is executed before the method that loads the listbox, but apparently does not run when I load text into the listbox.
This code is in the CellTextPaint Event
[code]
if bLate then
g.ForeColor = Color.Red
else
g.ForeColor = Color.Black
end if
Return False[/code]
This code loads the listbox from data in a RecordSet:
[code]dim sSQL As String
dim sMsg As String
dim i As Integer
dim sToday As String
dim sDue As String
sSQL = “SELECT * FROM Suspense WHERE Completed = 0 ORDER BY DueDate”
rs = dbSQL.SQLSelect(sSQL)
if dbSQL.Error then
sMsg = "Database Error reading Suspense Table - " + dbSQL.ErrorMessage
MsgBox(sMsg)
UpdateLog(CurrentMethodName, sMsg, “E”)
Return
end if
lbSuspense.DeleteAllRows
lbSuspense.ColumnType(3) = Listbox.TypeCheckbox
rs.MoveFirst
i = 0
while not rs.eof
dDueDate = rs.Field(“DueDate”).DateValue
sToday = dToday.ShortDate
sDue = dDueDate.ShortDate
if dDueDate.SQLdate <= dToday.SQLdate then
bLate = True
else
bLate = False
end if
lbSuspense.addRow
lbSuspense.RowTag(i) = rs.Field(“pkRecID”).IntegerValue
lbSuspense.cell( i, 0 ) = left(rs.Field(“DueDate”).StringValue, 10)
lbSuspense.cell( i, 1 ) = rs.Field(“Description”).StringValue
lbSuspense.cell( i, 2 ) = rs.Field(“Priority”).StringValue
if bLate then lbSuspense.Refresh
i = i + 1
rs.MoveNext
wend[/code]
The listbox loads except the text of the late item is not red. And since I would never ever let a task go past due, I forced a test record to be late…