user645850
user645850

Reputation: 1

I want to clear one item in listbox winforms c#

I want to clear one item in a listbox winforms c#.

How can I get the index of the item?

Upvotes: 0

Views: 941

Answers (1)

as-cii
as-cii

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

Related Questions