Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically selecting items in a WPF ListView

Tags:

listview

wpf

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

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.

like image 886
Diego Mijelshon Avatar asked Jul 07 '10 19:07

Diego Mijelshon


1 Answers

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

like image 177
STO Avatar answered Oct 13 '22 11:10

STO