I have a WPF application and am using the WPF toolkit autocomplete box in VS 2008. I am getting inconsistent results for the SelectedItem property.
My ItemSource data is like the following (in an object)
Address X - Person A
Address X - Person B
So its two records, with the same address but each record has a different person listed. My searches in the autocomplete box are by address (which is also my ValueMemberPath). So when Address X is typed in, both of these names pop-up, no problems there. However, if I were to choose Person B from the drop-down list (i.e. the second record) the SelectedItem property is ALWAYS the object for Person A. No matter how I select the records or what not, SelectedItem is always Person A, I can never get SelectedItem to return Person B.
What am I doing wrong?
When selecting items by value in an AutocompleteBox/ListBox/ComboBox you should make sure the selected value is unique in the list of items (like an ID of some sort), because the control doesn’t know which item to choose when there are two items with the same key property. So it sends a random one (the first, since this isn’t actually an expected use case) back to the viewmodel.
It’s the same problem you’d have when I told you that there were two possible items (“Kendo Suit”, “Keyboard”) from which I owned the one that started with a ‘K’ and you had to tell me which item I meant.
I hope my example is comprehensible enough 😉