How can I unselect item in ListView?

后端 未结 8 1133
故里飘歌
故里飘歌 2021-01-08 01:19

I have a ListView with a couple of items in it. When the ListView looses focus, the last selected ListViewItem is still \"selected\" with a gray background.
I would like

8条回答
  •  南方客
    南方客 (楼主)
    2021-01-08 01:32

    I know this is late but in case someone else needed the solution I would like to add to the solution.

    You need to set the Focused property to false to avoid deselected items having focus.

    for (int i = 0; i < this.myListView.SelectedIndices.Count; i++)
    {
        this.myListView.Items[this.myListView.SelectedIndices[i]].Selected = false;
        this.myListView.Items[this.myListView.SelectedIndices[i]].Focused = false;
    }
    

提交回复
热议问题