I am trying to remove an item from listbox but is not working. even that im sure that there exist an item to remove. any idea about what maybe going wrong?
iSelectedItem = ContactConflictListBox.ItemIndex;
if ((iSelectedItem == -1))
{
return;
}
ContactConflictListBox.Items.Remove(iSelectedItem);
You are getting an index, not an item. To remove by index, use
ContactConflictListBox.Items.Remove(ContactConflictListBox.Items[iSelectedItem]);orContactConflictListBox.Items.RemoveAt(iSelectedItem);. Be aware, that the RemoveAt method shouldn’t be used in code, it’s just there for infrastructural reasons.