tags:

views:

15

answers:

1

How can I set the selected items in a WPF ListView programatically?

Basically, I have a List<SomeEntity> and a ListView that is bound to another List<SomeEntity>. I need to mark the items that exist on the first list as selected.

+1  A: 
var lv = yourListView;
lv.SelectedItems.Clear();
foreach(var item in selection)
     lv.SelectedItems.Add(item);

http://msdn.microsoft.com/en-us/library/system.windows.controls.listbox.selecteditems.aspx

STO
It should have been obvious now that I look at it. The documentation was misleading, as it says the property **gets** a list of selected items, without mentioning it can also be used to **set** them. Thanks!
Diego Mijelshon