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.
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.
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