Skip to content

Store checked items from CheckComboBox in a string array

TAN WhoAMI

Asked Jan 15, 2014, 2:57 PM EST9 answers
Share
LinkedInX

From the Extended WPF Toolkit, we have the CheckComboBox.
in a ItemsSelectionChanged event, I wish to store those checked items in a string array, is that possible?
I try below:

it does not work according to my needs:
say "abc" and "def" items were checked.
it gives me selectedCostCenter[0]=abc,def
what I need is:
selectedCostCenter[0]=abc
selectedCostCenter[1]=def

how do I modify the code for my needs?
thanks.

Code below:
C#
    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 (i = 0; i < SelectedItemsTotal; i++)
            {
                selectedCostCenter[i] = CheckComboBox_CostCenter.SelectedValue.ToString();
            }
         }

9 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Biswa Pujarini Mohapatra
    0

    modify your code to


    C#
    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 (i = 0; i < SelectedItemsTotal; i++)
                {
                    selectedCostCenter[i] = CheckComboBox_CostCenter.Items[i].ToString();
                }
             }
    0
  • Biswa Pujarini Mohapatra
    0

    modify your code to


    C#
    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 (i = 0; i < SelectedItemsTotal; i++)
                {
                    selectedCostCenter[i] = CheckComboBox_CostCenter.Items[i].ToString();
                }
             }
    0
  • 0
    thanks for the modified code. another thing, how do I checked say the first item on Windows Loaded? I try below, but it does not work. strange ...

          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.SelectedItems.Add("Analog");    
            }
    0
  • Biswa Pujarini Mohapatra
    0

    use this

    CheckComboBox_CostCenter.SetItemChecked(0, true);


    Exposed the SetItemChecked(int index, bool isChecked) method so that you can programmatically set an item as checked

    0
  • 0
    what should be inside the function for
    SetItemChecked(int index, bool isChecked)?
    0
  • Biswa Pujarini Mohapatra
    0


    no need to expose that method that's an info


    I have modified your code use this

    C#
    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.SelectedItems.Add("Analog");
    CheckComboBox_CostCenter.SetItemChecked(0, true);
            }


    hope it helps

    0
  • 0
    Error 1 'Xceed.Wpf.Toolkit.CheckComboBox' does not contain a definition for 'SetItemChecked' and no extension method 'SetItemChecked' accepting a first argument of type 'Xceed.Wpf.Toolkit.CheckComboBox' could be found (are you missing a using directive or an assembly reference?) C:\DriveD\TESTS4WORK\TestSystemUtilisation\MainWindow.xaml.cs 73 38 TestSystemUtilisation
    0
  • Biswa Pujarini Mohapatra
    0


    I have no idea that you are using xceed WPF toolkit I gave solution for normal windows application


    here is your code

    C#
     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.SelectedItem= "Analog";
            }
    0
  • 0
    from my first discussion, I mentioned that I am using Extended WPF Toolkit. Normal window application does not allow us to have CheckComboBox, just the normal ComboBox.
    0