Hi,
I have a combobox whose itemstemplate is a check box whos itemsource is a collection of objects, say a Person.
Each person has a name and so this will be the checkboxes content.
However now I want to find out which checkbox in the comboboxs' collection is checked, though when I call - (this.MainComboBox.Item[i] as CheckBox).IsChecked - fails because there is "no" check box.
How do I access the IsChecked property of the items in the combobox given that the item source is a collection on objects?
Thanks greatly in advance.
Person.
Loading

Sam HobbsRank #107 · 20.5K reputationPosted Dec 7, 2009, 9:56 AM EST
You can use the SelectedItem member to get the selected item without using a checkbox.
person91 reputationPosted Dec 9, 2009, 1:50 AM EST
Thanks,
Person
Piotr Justyna70 reputationPosted Dec 9, 2009, 6:36 AM EST
please try to extend your collection's items with a property "IsChecked" bound to a "IsChecked" status of each checkbox.
person91 reputationPosted Dec 9, 2009, 7:23 AM EST
Basically the itemtemplate contains the checkboxes, i dont see why i can access these even though the itemssource of the combobox is a collection of people. Essentially each person object has its name bound to the checkbox content property, is there no -- (combobox.Items[0].HostingComponent as CheckBox).IsChecked???
Thanks greatly in advance.
Person.
Piotr Justyna70 reputationPosted Dec 9, 2009, 2:24 PM EST
I don't think there is a technical posibility to do what you want. This sounds a bit like breaking all best practices :) If you insist (and you don't want to extent your class), you can also keep a separate list of Bools for every checkbox and keeping up to date subscribing to each checkbox click event.
Please let me know if this was helpful.
Sam HobbsRank #107 · 20.5K reputationPosted Dec 10, 2009, 8:38 AM EST