Gern Blanston
Gern Blanston

Reputation: 42660

listview select item backcolor

Do I programmatically have to manage the backcolor\highlight color on a Listview's item when selected through code?

So if I do this: listView1.Items[1].Selected = true;

Do I also need to do this, so it looks highlight, as it does when selected with a mouse click: listView1.Items[1].BackColor = Color.Blue;

(and clear it when the selection changes)

I would have thought that Selected = true would also do the 'backcolor\highlighting' that happens through the mouse click. Am I missing something?

Upvotes: 1

Views: 5744

Answers (2)

jheddings
jheddings

Reputation: 27573

You do not need to handle the highlighting code yourself, but the item will only appear highlighted if the ListView control has focus. Add listView1.Select() after you select the item and see if that helps.

Otherwise, you'll need to set the HideSelection property on the ListView to false.

Upvotes: 2

Matt Breckon
Matt Breckon

Reputation: 3374

Has the control got focus? If not the default setting is to hide the selection when the control doesn't have focus - see the HideSelection property.

Upvotes: 2

Related Questions