What is the most efficient way to delete all selected items in a ListViewItem collection

Posted by Andrew on Stack Overflow See other posts from Stack Overflow or by Andrew
Published on 2009-01-17T10:44:23Z Indexed on 2013/11/07 21:56 UTC
Read the original article Hit count: 176

Filed under:
|
|
|

My user is able to select multiple items in a ListView collection that is configured to show details (that is, a list of rows).

What I want to do is add a Delete button that will delete all of the selected items from the ListViewItem collection associated with the ListView.

The collection of selected items is available in ListView.SelectedItems, but ListView.Items doesn't appear to have a single method that lets me delete the entire range. I have to iterate through the range and delete them one by one, which will potentially modify a collection I'm iterating over.

Any hints?

Edit: What I'm basically after is the opposite of AddRange().

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms