In windows forms it is easy to select an item from a listview as:
myListView.items[index].selected = True;
on wpf it is not the same. I am binding a List to myListView. as a result I am not able to cast a someClass object to ListViewItem in order to call the IsSelected method. In other words this will not work:
foreach (ListViewItem item in listView1.Items)
{
item.IsSelected = true;
}
because item cannot be treated as a ListViewItem. How can I select items then? I am able to select all the items though by calling myListView.selectAll() method.
how can I select a single object on my listview programmaticaly.
In most cases you are supposed to bind the selection to some property on your object. e.g.
Then setting that property in code will select the item:
You also can manipulate the
SelectedItemscollection: