Programmatically select items in a WPF ListView

How to programmatically set selected items in a WPF ListView?

Essentially, I have a List<SomeEntity> and a ListView that is linked to another List<SomeEntity> . I need to mark the elements that exist in the first list as selected.

+7
listview wpf
source share
1 answer
 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

+11
source share

All Articles