After a user clicks on any number of items in a CheckedListBox, I want to programmatically remove the checks on those items when the window is closed. With the CheckedListBox named lstChoices, I have:
For I As Integer = 0 To lstChoices.SelectedItems.Count - 1
Dim lbi As Xceed.Wpf.Toolkit.Primitives.SelectorItem = CType(lstChoices.ItemContainerGenerator.ContainerFromIndex(I), Xceed.Wpf.Toolkit.Primitives.SelectorItem)
lbi.IsSelected = False
Next
The problem is that the SelectedItems property is NOT the selected items. Oddly, the SelectedItems.Count property is computed correctly but the loop just goes through the first ListBoxItems up to Count whether they are selected or not.
The documentation says the SelectedItems property "Gets the collection of checked items". Either the documentation is wrong or there's a bug in that control. How can I get just the checked items.
You are currently iterating over the
Itemscollection asContainerFromIndexreturns an item based on theItemsproperty and not theSelectedItemsproperty.You should iterate the
SelectedItemsand uselstChoices.ItemContainerGenerator.ContainerFromIteminstead: