Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top