code_junkie

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

Nov 13th, 2011
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. ListView listview = <reference to ListView>;
  2. foreach (ListViewItem item in listView.SelectedItems)
  3. {
  4. item.Remove();
  5. }
  6.  
  7. var ItemsToDelete = ... // wherever you get the collection of items to delete from
  8. var RemainingItems = yourList.FindAll(delegate(ListItem x) {
  9. return !ItemsToDelete.Contains(x)
  10. });
  11. yourListView.DataSource = RemainingItems;
  12. yourListView.DataBind();
Add Comment
Please, Sign In to add comment