I am trying to use this method that is ran from a button click that will retrieve the select item from a listbox then remove this item from the list. Whenever i run the code i get this error: "List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change.".
I'm completely stumped.
public void DeleteSale()
{
foreach (BootSale b in lstBootSales.SelectedItems)
{
lstBootSales.Items.Remove(b.Id);
lstBootSales.Items.Remove(b.Date);
DisplayAllBootSales();
}
}
DisplayAllBootSales();simply refreshes the listbox values afterwards
I have a List "BootSale" where I store information which is written to a listbox. I want to be able to click the item in the listbox then click delete and it will be completely removed from the system