Suppose you have a ListBox named listBox1. If you want to remove the selected item from it, use the Items.Remove() method, and pass as an argument the SelectedItem property:
listBox1.Items.Remove(listBox1.SelectedItem); |
However if the ListBox has the SelectionMode set to MultiExtended and you want to remove all the selected items, use the following code:
while(lstKeys.SelectedItems.Count > 0) { lstKeys.Items.Remove(lstKeys.SelectedItem); } |