public void SetTextComboBoxItemsList()
{
textComboBoxItems = new List<string>();
textComboBoxItems.Add("SelectAllExpect ALFKI");
textComboBoxItems.Add("ALFKI");
textComboBoxItems.Add("ANATR");
textComboBoxItems.Add("AROUT");
textComboBoxItems.Add("BLAUS");
textComboBoxItems.Add("BOLID");
textComboBoxItems.Add("BOTTM");
textComboBoxItems.Add("BERGS");
textComboBoxItems.Add("BLONP");
textComboBoxItems.Add("BONAP");
textComboBoxItems.Add("ANTON");
} |
protected override void OnComboBoxSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
ObservableCollection<string> ComboselectedItems = new ObservableCollection<string>();
ObservableCollection<string> selectedItems = new ObservableCollection<string>();
var comboBox = sender as ComboBoxAdv;
if ((e.AddedItems.Contains("SelectAllExpect ALFKI") && !comboBox.SelectedItems.Cast<string>().Contains("SelectAllExpect ALFKI")) || (e.AddedItems.Contains("SelectAllExpect ALFKI") && comboBox.SelectedItems.Cast<string>().Contains("SelectAllExpect ALFKI")))
{
foreach (string item in comboBox.ItemsSource)
{
if (item != "ALFKI")
selectedItems.Add(item);
}
comboBox.SelectedItems = selectedItems;
}
else if (!comboBox.SelectedItems.Cast<string>().Contains("ALFKI") && !comboBox.SelectedItems.Cast<string>().Contains("SelectAllExpect ALFKI") && comboBox.SelectedItems.Cast<string>().Count() == comboBox.Items.Count - 2)
{
foreach (string item in comboBox.ItemsSource)
{
if (item != "ALFKI")
selectedItems.Add(item);
}
comboBox.SelectedItems = selectedItems;
}
else if(!comboBox.SelectedItems.Cast<string>().Contains("ALFKI") && comboBox.SelectedItems.Cast<string>().Contains("SelectAllExpect ALFKI") && comboBox.SelectedItems.Cast<string>().Count() >= 1)
{
foreach (string item in comboBox.SelectedItems)
{
if (item != "SelectAllExpect ALFKI")
selectedItems.Add(item);
}
comboBox.SelectedItems = selectedItems;
}
else if(comboBox.SelectedItems.Cast<string>().Contains("ALFKI"))
{
foreach (string item in comboBox.SelectedItems)
{
if (item != "SelectAllExpect ALFKI")
selectedItems.Add(item);
}
comboBox.SelectedItems = selectedItems;
}
base.OnComboBoxSelectionChanged(sender, e);
}
|