I'm having problems removing the data in a list which was entered by a user in my textboxes and then stored in a listbox. I know how to remove the selected item in the listbox but when I click my button to show everything in the list, the selected item I just deleted is still in the list.
Here is my code for removing the selected item in the listbox:
for (int i = 0; i < VehicleListBox.SelectedItems.Count; i++)
VehicleListBox.Items.Remove(VehicleListBox.SelectedItems[i]);
My list is in a class called company and the list is named vehicles. I have looked everywhere for the most part for my answer and cannot seem to find it. I should also mention it's a generic list.
With your class design as I understand it, I wrote the following code in a WPF project. I added a listbox called "listbox1" and a button to the form. I believe the following code does what you want, or at least would guide you to the answer.