private void RemoveCombatant_Click(object sender, RoutedEventArgs e) { if (CombatantList.SelectedItem != null) { if (ActiveCombatant != null) { if (ActiveCombatant.Name.Equals((CombatantList.SelectedItem as DD4ECombatant).Name)) { var index = CombatantList.Items.IndexOf(ActiveCombatant); if (index >= CombatantList.Items.Count - 1) { ActiveCombatant = CombatantList.Items[0] as DD4ECombatant; } else { ActiveCombatant = CombatantList.Items[index + 1] as DD4ECombatant; } } } var removeIndex = CombatantList.SelectedIndex; CombatantList.SelectedIndex = -1; Combatants.RemoveAt(removeIndex); } }