This issue that is occurring is that whenever the RadComboBox’s ItemsSource property is changed the SelectedItem property is being set to null.
Requirements to recreate issue:
- Original ItemsSource is a collection of objects that ARE NOT value types
- SelectedValue is bound to some property
- SelectedValuePath is set
- SelectedItem is some item in the original ItemsSource
- New ItemsSource is a collection of objects of the same type as the original ItemsSource that does not contain a reference to the same object in memory as the current SelectedItem
What is happening is that when the new ItemsSource is set the RadComboBox is finding that none of the new items reference the same object in memory as the current SelectedItem and so setting the SelectedItem to null.
However, I have defined the SelectedValuePath so I clearly want the RadComboBox’s selection mechanism to be driven by the SelectedValue and not the SelectedItem. What I feel should be happening is that when the ItemsSource changes and the SelectedValuePath is not null the RadComboBox would then compare the value of the property at the SelectedValuePath of the SelectedItem to the value of the property at the SelectedValuePath for each item in the new ItemsSource. And only then, if it cannot find a match set the SelectedItem to null.
This issue was difficult to track down and has been particularly vexing for us because we are using the Csla framework in our project. When using this framework, whenever we perform an operation on a business object we are returned a COPY of that object not the original object. If that object happens to be a collection that a RadComboBox’s ItemsSource is bound to then the SelectedItem is getting wiped out.