Set selected index in list

I have a list in Win Forms where I need to programmatically set the selected index. Apparently, the ListView does not have a SelectedIndex property that can be set. Is there any other way to do this?

+4
source share
2 answers

Apparently, the ListView does not have a SelectedIndex property that can be set.

Indeed, this is logical, as you can select multiple items.

Therefore, it has a property SelectedItems, as well as a property SelectedIndices; both are read-only.

Selected true:

listView1.Items[someItemIndex].Selected = true; 

ListView MultiSelect false, . , .

, listView1.SelectedIndices.Clear(); listView1.SelectedItems.Clear();..

+9

, Selected, : this.listView1.Items[2].Selected = true;

Edit

, MultiSelect ListView false .

+3

Source: https://habr.com/ru/post/1619538/


All Articles