简体   繁体   中英

Color of Selected Item in ListView

I am writing listView1.Items[1].Selected = true; but it does not highlight that item....what is wrong? I also changed the HideSelection property to False, so now at least I can see some Gray highlight color, but where is the blue color? when I click with Mouse, it is blue, but when I set it with code as posted above , it is not blue... what am I doing wrong?

It's your Windows colors that are tricking you.
I just tested it, and with HideSelection set to false, I set the selected item, and I see that item turn grey, which is my Windows color definition for a selected item in an inactive control.
If you want it to turn blue, which is most likely the color of a selected item in an active control, set the focus to that ListView , saying listView1.Focus() , and you'll see that color you're talking about, but you've just changed the focus to it, so be careful.

listView1.Select();
listView1.Items[index].Selected = true;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM