Quantcast
Channel: wpftoolkit Discussions Rss Feed
Viewing all articles
Browse latest Browse all 2157

New Post: CheckComboBox enqueries

$
0
0
Hi BoucherS,

the first answer to (1) does not work. I have this and I do not see any of the first and second items being checked upon Windows_Loaded.

private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        //string[] CostCenterName = { "Analog", "Digital", "EMS", "INT1", "INT2", "INT3", "Photo", "QA", "SMT1", "SMT2", "US-PF", "US-PXS" };
        //CheckComboBox_CostCenter.ItemsSource = CostCenterName.ToList();
        //CheckComboBox_CostCenter.SelectedItemsOverride = new List<string>() { CostCenterName[0], CostCenterName[1] };
        List<string> myList = new List<string>() { "abc", "def", "ghi", "jkl" };
        CheckComboBox_CostCenter.ItemsSource = myList;
        CheckComboBox_CostCenter.SelectedItemsOverride = new List<string>() { myList[0], myList[1] };
        CheckComboBox_CostCenter.SelectedValue = "abc,def";
    }
For Part (2), the second part of your code works for your case.
but when I try to implement it for my case, such that it loads from a text file, it does not work. Say when I checked a item on CheckListBox_TestSystems, next choose another item to check on the CheckComboBox_CostCenter, it does add to the CheckListBox_TestSystems, with the initial checked item on CheckListBox_TestSystems still remain as checked. This is what I want.
But when I uncheck previously checked items on the CheckComboBox_CostCenter, those items which supposed to be removed from the CheckListBox_TestSystems still remain there. That means this part of the code ( CheckListBox_TestSystems.Items.Remove(stRead.ReadLine());) does not work.
   private void CheckComboBox_CostCenter_ItemSelectionChanged(object sender, Xceed.Wpf.Toolkit.Primitives.ItemSelectionChangedEventArgs e)
    {
        int SelectedItemsTotal = CheckComboBox_CostCenter.SelectedItems.Count;
        string[] selectedCostCenter = new string[SelectedItemsTotal];

        for (int j = 0; j < SelectedItemsTotal; j++)
        {
            selectedCostCenter[j] = CheckComboBox_CostCenter.SelectedItems[j].ToString();
            if (e.IsSelected)
            {
                if (e.Item.ToString() == selectedCostCenter[j])
                {
                    FileInfo file = new FileInfo(string.Concat(path1, selectedCostCenter[j], ".txt"));
                    StreamReader stRead = file.OpenText();
                    while (!stRead.EndOfStream)
                    {
                        CheckListBox_TestSystems.Items.Add(stRead.ReadLine());
                    }
                    stRead.Close();
                }
            }
            else
            {
                if (e.Item.ToString() == selectedCostCenter[j])
                {
                    FileInfo file = new FileInfo(string.Concat(path1, selectedCostCenter[j], ".txt"));
                    StreamReader stRead = file.OpenText();
                    while (!stRead.EndOfStream)
                    {
                        CheckListBox_TestSystems.Items.Remove(stRead.ReadLine());
                    }
                    stRead.Close();
                }
            }
        }
    }

Viewing all articles
Browse latest Browse all 2157

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>