dillion n
dillion n

Reputation: 69

C# ListBox deleting item

Hello I've read countless threads on removing ListBox items and I have tried many different methods but I still keep getting this bug.

When I try to remove an item and there is another item in the ListBox with the exact same name, it removes the other item. Here is a GIF explaining it.

the code I use to remove item from ListBox is below:

if (listBox1.SelectedItem != null) {
    listBox1.Items.Remove(listBox1.SelectedItem);
    utils.updateScript(script, listBox1);

    listBox1.SelectedItem = null;
}
else {
    MessageBox.Show("Please select a script command to delete");
}

Upvotes: 1

Views: 58

Answers (1)

dillion n
dillion n

Reputation: 69

Solution:

listBox1.Items.RemoveAt(listBox1.SelectedIndex);

this appears to be working!

Upvotes: 2

Related Questions