Coloring Text in a Listbox

Hey gang,

Having trouble figuring out how to set the color for specific cells in a listbox. I update the text in these cells and want to set them to a specific color after updating so that I can see that there’s been an update. I have the following code in the method that updates the text:

    For k as integer = 4 to 6
      DeviceList.CellType(i,k) = Listbox.TypeEditableTextField
      DeviceList.EditCell(i,k)
      Devicelist.ActiveCell.SelStart = 0
      DeviceList.ActiveCell.SelLength = DeviceList.ActiveCell.Text.Len
      DeviceList.ActiveCell.TextColor = &c0080FF00
    Next

DeviceList is my listbox. This is all happening in another For/Next loop that performs the action on each row (i).

When I do this, nothing happens. The text color is still black.

Thanks,

Jon

Because the cellTextPaint then fires and colors the text default black. You will need to set a boolean and, if True, color the text to &c0080FF00 in the cellTextPaint evant. Calling .invalidate on the LB will then get you your colors

Use the Listbox.CellBackgroundPaint event.

OK. Thanks guys…

CellBackground paint or CellTextPaint? I think it would be CellTextPaint if I am coloring the text…

[quote=153702:@Jon Ogden]CellBackground paint or CellTextPaint? I think it would be CellTextPaint if I am coloring the text…

[/quote]

CellTextPaint

OK. So in CellTextPaint, I am doing this;

          g.ForeColor = &c66CCFF00
          g.DrawString(me.Cell(row,column),x,y)

Still black. Do I need to set everything using ActiveCell like I did above? I thought i could just draw it in the paint event…

One more - so I did this now…

Dim t as string = me.cell(row,column) me.cell(row,column) = "" g.ForeColor = &c0080FF00 g.DrawString(t,x,y)

And that works, but it effectively eliminates the text in those fields and replaces with with a graphic instead. So that’s not going to work…

And if I start doing things like:

me.CellType(row,column) = Listbox.TypeEditableTextField me.EditCell(row,column) me.ActiveCell.SelStart = 0 me.ActiveCell.SelLength = me.ActiveCell.Text.Len me.ActiveCell.TextColor = &c0080FF00

I get all sorts of weird things happening…Rows selected that I can’t unselect, etc.

Sorry, didn’t read closely enough, thought you were drawing a box or something.

All you need to do in CellTextPaint is set the ForeColor, then return false. Xojo will take care of painting the text.

[quote=153719:@Kem Tekinay]Sorry, didn’t read closely enough, thought you were drawing a box or something.

All you need to do in CellTextPaint is set the ForeColor, then return false. Xojo will take care of painting the text.[/quote]

Hmm… Not working…

I see what’s happening. I’m using someone else’s subclass of listbox and they had some code in the paint event…

I ran a test to confirm my memory before posting and it worked like a charm here. Want me to send you a demo project?

No. I got it. I’m using the CustomCellListbox class from either Restrepo or Ballman (forget who) and they set the forecolor to black always in the celltextpaint event of the super for my class. I just fixed it…

It should set it to black, then raise the subclass event so you can modify it if needed. I trust that’s what you did.

bascically

this methode needs conditional texting while painting because otherwise it doesn’t handle reordering of the rows correctly.