This is a migrated thread and some comments may be shown as answers.

RadComboBox ItemsSource Refresh removes selectedValue Binding

1 Answer 321 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Rick Knicely
Top achievements
Rank 1
Rick Knicely asked on 09 Dec 2010, 08:39 PM
Hello,
I have a RadComboBox bound to an ItemsSource that is an ObservableCollection.  When that ObserableCollection is changed the RadComboBox SelectedValue is set to -1 instead of the binding in the SelectedValue.  The underlying object is not changed and still has the correct value.

Here is my binding.
<telerik:RadComboBox Name="cmbLocation"    Margin="0 8 0 0"  IsEditable="False" Width="95" ItemsSource="{Binding Lookup.LuLocation}"  DisplayMemberPath="LocationDescription" SelectedValuePath="LocationId" SelectedValue="{Binding Path=Line.LocationId, Mode=TwoWay}" HorizontalAlignment="Left" />

How do I keep the binding as the ObservableCollection changes?


Thank you,
Rick

1 Answer, 1 is accepted

Sort by
0
Rick Knicely
Top achievements
Rank 1
answered on 10 Dec 2010, 03:03 PM
I was able to resolve this by using the SelectionChanged event.
The underlying object is not changed when the ObservableCollection bound to the ItemsSource property changes. All I had to do is re-create the SelectedValue binding in code. I set the e.Handled to true so the event will not bubble.

        private void Cmb_ItemsSource_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            RadComboBox rcb = sender as RadComboBox;
            if (rcb.SelectedIndex == -1)
            {            
                rcb.SetBinding(RadComboBox.SelectedValueProperty, "Line.LocationId");
                e.Handled = true;
            }
        }
Tags
ComboBox
Asked by
Rick Knicely
Top achievements
Rank 1
Answers by
Rick Knicely
Top achievements
Rank 1
Share this question
or