Well I’ve got this very close to what I want but have reached another impasse.
To explain the code below the text in column 1 (ie. the 2nd column) has a name with an ‘account type’ in brackets afterwards. So it might be “Richard Brown (Newbie)” or “Dave S (Genius)” or “Richard Summers (Crackpot)” - that kind of thing - and I want the bracketed text in another colour.
So… so far in the CellTextPaint event of my ListBox I have:
IF column = 1 then
dim i as integer
dim n as integer
dim celltext as string
dim startstring as string
dim endstring as string
for i=0 to me.ListCount-1
celltext=me.Cell(i,1)
n = InStr(celltext, "(")
startstring = Left(celltext,n-1)
endstring = Right(celltext, Len(celltext)-n + 1)
g.forecolor=&c000000
g.drawstring (startstring,0,g.textascent)
g.forecolor=&c888888
g.drawstring (endstring,g.stringwidth(startstring),g.textascent)
Return True
next i
end if
Which works beautifully except it puts the value from the first row into every row!
for i=0 to me.ListCount-1
celltext=me.Cell(i,1)[/quote]
CellTextPaint is called individually for each cell but that loop starts out processing row 0 each time, then hits the return true before any more. Instead remove the loop and use the Row parameter to get the current cells text…
IF column = 1 then
dim n as integer
dim celltext as string
dim startstring as string
dim endstring as string
celltext=me.Cell(row,column) // change the "1", just for portability sake :)
n = InStr(celltext, "(")
startstring = Left(celltext,n-1)
endstring = Right(celltext, Len(celltext)-n + 1)
g.forecolor=&c000000
g.drawstring (startstring,0,g.textascent)
g.forecolor=&c888888
g.drawstring (endstring,g.stringwidth(startstring),g.textascent)
Return True
end if
also… the code ASSUMES there will always be a “(”…