Combobox with collection view itemssource does not update selection box item on changes to the Model
Posted
by Vinit Sankhe
on Stack Overflow
See other posts from Stack Overflow
or by Vinit Sankhe
Published on 2010-04-29T02:21:40Z
Indexed on
2010/04/29
2:27 UTC
Read the original article
Hit count: 885
Hello,
Sorry for the earlier lengthy post. Here is my concise (!) description.
I bind a collection view to a combobox as a itemsSource and also bind its selectedvalue with a property from my view model. I must keep IsSynchronizedWithCurrentItem="False".
I change the source list ofr the view and then refresh the view. The changed (added, removed, edited) items appear correctly in the item list of the combo. But problem is with the selected item. When I change its property which is also the displaymember path of the combo, the changed property value does not reflect back on the selecton box of the combo. If you open the combo dropdown it appears correctly on the item list but not on the selection box.
Now if I change the combobox tag to Listbox in my XAML (keeping all attributes as it is) then when selected item's displaymember property value is updated, the changes reflect back on the selected item of the list box .
Why this issue?
Just FYI:
My View Model has properties EmployeeCollectionView and SelectedEmployeeId which are bound to combo as ItemsSource and SelectedValue resp. This VM implements the INotifyPropertyChanged interface.
My core employee class (list of which is the source for the EmployeeCollectionView) is simply a Model class without INotifyPropertyChanged.
DisplayMemberPath is "Name" property of employee Model class. I change this by some means and expect the combo selection box to update the value.
I tried refreshing ther SelectedEmployeeId by setting it 0 (where it correctly selects the dummy "-- Select All --" employee entry from itemsSource) and old selected value back. But no use. The old value takes me back to the old label. Items collection has latest entry though.
When I make combobox's IsEditable=True before the view's refresh and after refresh I make IsEditable=False then the things work out correctly!
But this is a patch and is unnecessary.
Thx
Vinit Sankhe
© Stack Overflow or respective owner