Search code examples
c#listboxitems

Removing more than 1 item in listbox


please help me how can remove more than 1 item in a listbox.I know the code for removing 1 item: listbox.Items.RemoveAt(i) but for more than 1 item selected in a listbox,what is the code? write the code for example in button-click event.I have only a button and a listbox in my winform.(write codes in C#)


Solution

  • while(listbox.SelectedItems.Count > 0)
     {
        listbox.Items.Remove(listbox.SelectedItem);
     }