private static void SetUpComboBox( ref int counter, ref int lastNumber, ref Dictionary<string, int> searched, SearchCombos searchCombos, ComboBox comboBox) { if (searched == null) { searched = new Dictionary<string, int>(); foreach (string item in searchCombos.items) { int current = counter++; searched.Add(item, current); if (String.Equals(item, searchCombos.last)) { lastNumber = current; } } } KeyValuePair<string, int>[] searched2 = new KeyValuePair<string, int>[searched.Count]; int i = 0; foreach (KeyValuePair<string, int> item in searched) { searched2[i++] = item; } Array.Sort(searched2, delegate (KeyValuePair<string, int> l, KeyValuePair<string, int> r) { return l.Value.CompareTo(r.Value); }); foreach (KeyValuePair<string, int> item in searched2) { comboBox.Items.Add(item.Key); if (item.Value == lastNumber) { comboBox.SelectedItem = item.Key; } } }
public SearchCombos(SearchCombos orig) { this.items = orig.items; this.last = orig.last; }