sooprise
sooprise

Reputation: 23187

ListBoxItem with modified background can't indicate whether its selected?

on a ListBox's DrawItem event, I set the background color of each ListBoxItem like so:

g.FillRectangle(new SolidBrush(Color.LightYellow), e.Bounds);

The only problem I'm having now, is after I change the background color, I can't tell when a ListBoxItem with a modified background color is selected. In other words, after a ListBoxItem has a modified background color, when I try to select it, its background color doesn't change to blue to indicated it is selected.

How can I have my cake and eat it too, by having my ListBoxItems with modified backgrounds indicate whether they are selected or not too?

Upvotes: 1

Views: 234

Answers (1)

dlev
dlev

Reputation: 48596

You should be inspecting the State member of the DrawItemEventArgs parameter to your handler to determine whether or not the item is selected (or focused, etc.) and then draw the background as you see fit.

This link has a good example of how to do that.

Upvotes: 2

Related Questions