tags:

views:

472

answers:

3

Hi,

I am figuring out a way to Select Multiple items in list view and deleting them on a certain action. What i can't figure out is, how should I have these multiple items selected? I would think there is a list that i would need to add them all into, but what's the best way to approach this situation, do you have any ideas? Thanks! -Kevin

+1  A: 

Set SelectionMode to Multiple or Extended

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

And iterate through your SelectedItems in your Listview! ;)

Arcturus
A: 

You can do one of the following...

ListView.SelectionMode = SelectionMode.Extended in code-behind or

<ListView SelectionMode="Extended"></ListView> in XAML

you also have 'multiple' selectionMode yet you could rather go for 'extended' which allows the user to select multiple items only using shift modifier.

For deleting the items selected you could use the ListView.SelectedItems Propery as follows

while( myListView.SelectedItems.Count > 0 )
{
    myListView.Items.Remove(list.SelectedItems[0]);
}

[or you could use the SelectedIndices property]

Hope this will avoid the issue you encountered :)

Cheers!

Veer
A: 

I would suggest do not use SelectedItems property of list view, instead bind the Selected property of the single ListView item, to a corresponding ViewModel class. After this, the only thing you need to do is to find all ViewModel object that have binded Selected property TRUE, remove them from model collection (if you do remove) and refresh UI. If the colelction is ObservableColelction, the UI will be refreshed automatically. Good Luck.

Tigran