RadComboBox ItemsSource Refresh removes selectedValue Binding

2 posts, 0 answers
  1. Rick Knicely
    Rick Knicely avatar
    43 posts
    Member since:
    Apr 2010

    Posted 09 Dec 2010 Link to this post

    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
  2. Rick Knicely
    Rick Knicely avatar
    43 posts
    Member since:
    Apr 2010

    Posted 10 Dec 2010 Link to this post

    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;
                }
            }
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top