Reputation: 1
I want to clear one item in a listbox winforms c#.
How can I get the index of the item?
Upvotes: 0
Views: 941
Reputation: 13019
ListBox
has a property called SelectedIndex
. To remove current selected item you have just to call RemoveAt(int)
method.
Example:
int selectedIndex = myListBox.SelectedIndex;
if(selectedIndex >=0)
myListBox.Items.RemoveAt(selectedIndex);
Upvotes: 3