4

I have a list view in windows forms. _listView1. I wish to programatically select an item in the listview. I say _listView1.Items[i].Select=true;

But that doesn't solve the problem. The item doesn't get selected.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Vi137
  • 248
  • 2
  • 10
  • possible duplicate of [How to select an item in a ListView programmatically?](http://stackoverflow.com/questions/5791235/how-to-select-an-item-in-a-listview-programmatically) – Soner Gönül Apr 08 '13 at 10:59
  • possible duplicate of [C#: Is there a way to SET the selected index of an item in listview at runtime?](http://stackoverflow.com/questions/817309/c-is-there-a-way-to-set-the-selected-index-of-an-item-in-listview-at-runtime) – CloudyMarble Apr 08 '13 at 10:59
  • Thanks for the replies Soner Gonul, TwoMore and user2025312. The Select was a typo. Apologies. I had "Selected" in my code.And I tried the steps mentioned in the links specified for no luck and then posted this question. – Vi137 Apr 08 '13 at 11:09

3 Answers3

3

The property is Selected, not Select:

_listView1.Items[i].Selected = true;
Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
  • Thanks Grant Thomas. Select was a typo. I had used Selected only and the problem persists – Vi137 Apr 08 '13 at 11:10
0

Try this: _listView1.selectedIndex = i;

Armen Mkrtchyan
  • 921
  • 1
  • 13
  • 34
0

Just use ListViewItem.Selected property;

_listView1.Items[i].Selected = true;

Gets or sets a value indicating whether the item is selected.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364