private void FillLists(MPListView availList, MPListView preferredList, string preferredLanguages, Dictionary<String, String> languages) { availList.Items.Clear(); preferredList.Items.Clear(); string[] preferredLanguageKeys = preferredLanguages.Split(';'); // fill preferredList with the preferred languages foreach (string key in preferredLanguageKeys) { if (!String.IsNullOrEmpty(key) && languages.ContainsKey(key) && !preferredList.Items.ContainsKey(key)) { ListViewItem item = new ListViewItem(new string[] { languages[key], key }) { Name = key }; preferredList.Items.Add(item); } } // fill availList with the rest of them foreach (KeyValuePair<string, string> kv in languages) { if (!availList.Items.ContainsKey(kv.Key) && !preferredList.Items.ContainsKey(kv.Key)) { ListViewItem item = new ListViewItem(new string[] { kv.Value, kv.Key }) { Name = kv.Key }; availList.Items.Add(item); } } availList.ListViewItemSorter = new ListViewColumnSorter() { SortColumn = 0, Order = SortOrder.Ascending }; availList.Sort(); }
private void FillLists(MPListView availList, MPListView preferredList, string preferredLanguages, List<KeyValuePair<string, string>> languages) { availList.Items.Clear(); preferredList.Items.Clear(); foreach (KeyValuePair<string, string> kv in languages) { ListViewItem item = new ListViewItem(new string[] { kv.Value, kv.Key }); item.Name = kv.Key; MPListView list; if (preferredLanguages.Contains(item.Name)) list = preferredList; else list = availList; if (!list.Items.ContainsKey(item.Name)) { list.Items.Add(item); } } availList.ListViewItemSorter = new ListViewColumnSorter() { SortColumn = 0, Order = SortOrder.Ascending }; availList.Sort(); }