How can I remove a selected item from a listview?
Well, although it's a lot late, I crossed that problem recently, so someone might cross with this problem again. Actually, I needed to remove all the selected items, but none of the codes above worked for me. It always throws an error, as the collection changes during the foreach. My solution was like this:
while (listView1.SelectedIndex > 0)
{
listView1.Items.RemoveAt(listView1.SelectedIndex);
}
It won't throw the error as you get position of the last selected item (Currently), so even after you remove it, you'll get where it is now. When there is no items selected anymore, the SelectedIndex returns -1 and ends the loop. This way, you can make sure that there is no selected item anymore, nor that the code will try to remove an item in a negative index.