Diego Mijelshon
Diego Mijelshon

Reputation: 52745

Programmatically selecting items in a WPF ListView

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.

Upvotes: 11

Views: 12395

Answers (1)

STO
STO

Reputation: 10638

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

Upvotes: 20

Related Questions