Dear Friend,
I am giving you the solution to delete one or more than one item.
For multiple selection of Items, you need to set the .SelectionMode property:
listBox1.SelectionMode = SelectionMode.MultiExtended;
Next, I am assuming that you have added the Items to your ListBox programmatically rather than using a DataSource (you wouldn't be able to remove them from the Items collection directly if the ListBox is using a DataSource).
It is done n the reverse order just in order to complete the operation of deletion successfuly
.
All you need to do is use the .RemoveAt() method, in reverse order (it is important to do it backwards, otherwise they won't be removed properly):-
for (int i = listBox1.SelectedIndices.Count-1; i >= 0; i--)
{
listBox1.Items.RemoveAt(listBox1.SelectedIndices[i]);
}
OR
for (int i = 0; i < listBox1.SelectedItems.Count; i++)
{
listBox1.Items.Remove(listBox1.SelectedItems[i].ToString());
i--;
}