There is a code
List<object> tmp = new List<object>(); foreach (object Item in listBoxPlaneType.SelectedItems) tmp.Add(Item); foreach (object Item in tmp) listBoxPlaneType.Items.Remove(Item); tmp.Clear(); which very well removes selected items from the listBoxPlaneType listBoxPlaneType
this macrame is outofrange
List<object> tmp = new List<object>(); List<int> tmp2 = new List<int>(); foreach (object Item in listBoxPlaneType.SelectedItems) tmp.Add(Item); foreach (int Item2 in listBoxPlaneType.SelectedIndices) tmp2.Add(Item2); foreach (object Item in tmp) listBoxPlaneType.Items.Remove(Item); foreach (int Item2 in tmp2) listBoxNumber.Items.RemoveAt(Item2); tmp.Clear(); tmp2.Clear(); Which should delete the selected items from the first listbox (which it does) and delete the items from the second listbox to the addresses selected in the first listbox.
Choose a full name and delete, then the number should be removed to the right. Sometimes it does not throw out with an error, but removes the wrong ones from the license plate.
I know that there is a sensitive problem with the circulation on the index (I hope so), but the offset by +1 and -1 does not help.
UPD: Added result
work with an error if I try to remove Il 2 and Outlaw 1
tmp.Clear();Do you think GC is dumber than you? - Alex78191RemoveAtremoves by index. After removing one item, the remaining indexes change. - Alexander Petrov