I have two ListBoxes, lstAvailableColors and lstSelectedColors. Between each listbox are two buttons, Add and Remove. When a color or colors is selected in lstAvailableCol
Example on how to remove the selected Items. Here only the selected indices are taken and removed.
public void RemoveSelectedItems(ListBox listbox)
{
List items = GetSelectedItems(listbox);
foreach (var listItem in items)
{
listbox.Items.Remove(listItem);
}
}
public List GetSelectedItems(ListBox listbox)
{
int[] selectedIndices = listbox.GetSelectedIndices();
return selectedIndices.Select(index => listbox.Items[index]).ToList();
}