I am trying to remove multiple selected items in a listbox, this code isnt working:
Not all selected items get removed, but most of them do.Code:private void btnRemove_Click(object sender, System.EventArgs e) { for (int x = 0; x < lstFiles.Items.Count; x++) { if (lstFiles.SelectedIndices.Contains(x)) { lstFiles.Items.RemoveAt(x); } } }
edit: seems its the first thing selected that doesnt get removed.




Reply With Quote