private void SelectedIndexChangedEvent(ComboBox combo, SettingsList <StaticMod> listSettingsMods, IList <ExplicitMod> listExplicitMods, IList <ComboBox> listCombo, IList <int> listSelectedIndex, int indexAA, bool selectEither) { int selectedIndexLast = listSelectedIndex[indexAA]; if (AddItemSelected(combo)) { StaticMod itemNew = listSettingsMods.NewItem(this, null, null); if (!Equals(itemNew, null)) { listSettingsMods.Add(itemNew); string itemAdd = (string)combo.SelectedItem; LoadLists(listSettingsMods, listExplicitMods, listCombo, indexAA, itemNew.GetKey(), selectEither); // If the selection was not successfully set to the new modification, // return to the previous selection. if (Equals(combo.SelectedItem, itemAdd)) { combo.SelectedIndex = selectedIndexLast; } } else { // Reset the selected index before edit was chosen. combo.SelectedIndex = selectedIndexLast; } } else if (EditListSelected(combo)) { IEnumerable <StaticMod> listNew = listSettingsMods.EditList(this, null); if (listNew != null) { listSettingsMods.Clear(); listSettingsMods.AddRange(listNew); string selectedItemLast = null; if (selectedIndexLast != -1) { selectedItemLast = combo.Items[selectedIndexLast].ToString(); } LoadLists(listSettingsMods, listExplicitMods, listCombo, indexAA, selectedItemLast, selectEither); } else { // Reset the selected index before edit was chosen. combo.SelectedIndex = selectedIndexLast; } } listSelectedIndex[indexAA] = combo.SelectedIndex; }
private void SelectedIndexChangedEvent(ComboBox combo, SettingsList <StaticMod> listSettingsMods, IList <ExplicitMod> listExplicitMods, IList <ComboBox> listCombo, IList <int> listSelectedIndex, int indexAA, bool selectEither) { int selectedIndexLast = listSelectedIndex[indexAA]; if (AddItemSelected(combo)) { StaticMod itemNew = listSettingsMods.NewItem(this, null, null); if (!Equals(itemNew, null)) { listSettingsMods.Add(itemNew); string itemAdd = (string)combo.SelectedItem; LoadLists(listSettingsMods, listExplicitMods, listCombo, indexAA, itemNew.GetKey(), selectEither); // If the selection was not successfully set to the new modification, // return to the previous selection. if (Equals(combo.SelectedItem, itemAdd)) { combo.SelectedIndex = selectedIndexLast; } } else { // Reset the selected index before edit was chosen. combo.SelectedIndex = selectedIndexLast; } } else if (EditCurrentSelected(combo)) { StaticMod itemEdit; if (listSettingsMods.TryGetValue((string)combo.Items[selectedIndexLast], out itemEdit)) { StaticMod itemNew = listSettingsMods.EditItem(this, itemEdit, listSettingsMods, null); if (!Equals(itemNew, null)) { int i = listSettingsMods.IndexOf(itemEdit); listSettingsMods[i] = itemNew; LoadLists(listSettingsMods, listExplicitMods, listCombo, indexAA, itemNew.GetKey(), selectEither); } } combo.SelectedIndex = selectedIndexLast; } else if (EditListSelected(combo)) { IEnumerable <StaticMod> listNew = listSettingsMods.EditList(this, null); if (listNew != null) { listSettingsMods.Clear(); listSettingsMods.AddRange(listNew); string selectedItemLast = null; if (selectedIndexLast != -1) { selectedItemLast = combo.Items[selectedIndexLast].ToString(); } LoadLists(listSettingsMods, listExplicitMods, listCombo, indexAA, selectedItemLast, selectEither); } else { // Reset the selected index before edit was chosen. combo.SelectedIndex = selectedIndexLast; } } else { string modName = (string)combo.SelectedItem; StaticMod staticMod; if (!string.IsNullOrEmpty(modName) && listSettingsMods.TryGetValue(modName, out staticMod)) { if (!EnsureLinkedPeptide(staticMod, indexAA)) { combo.SelectedIndex = selectedIndexLast; } } } listSelectedIndex[indexAA] = combo.SelectedIndex; }