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 HobbsPosted Dec 10, 2009, 1:38 PM
Piotr JustynaPosted Dec 9, 2009, 7:24 PM
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.
personPosted Dec 9, 2009, 12:23 PM
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 JustynaPosted Dec 9, 2009, 11:36 AM
please try to extend your collection's items with a property "IsChecked" bound to a "IsChecked" status of each checkbox.
personPosted Dec 9, 2009, 6:50 AM
Thanks,
Person
Sam HobbsPosted Dec 7, 2009, 2:56 PM
You can use the SelectedItem member to get the selected item without using a checkbox.