RadComboBox Selection from Binding Problems

5 posts, 0 answers
  1. igal a
    igal a avatar
    28 posts
    Member since:
    Oct 2009

    Posted 30 Dec 2010 Link to this post

    i am working with version 2010.3.1110.35
    i have this in the listbox itemTemplate

    <

     

    telerik:RadComboBox x:Name="FieldComboBox" Grid.Column="0" ItemsSource="{Binding Fields}" SelectedItem="{Binding Field,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

     

     



    Field returns a class that implements

    INotifyPropertyChanged



    and Fields returns a List<Field>



    now when i ran the application, if i set a breakpoint on get field, i can see it is trying to get it,
    and that the value returned is correct

    but when gui is finished loading

    selectedindex is set to -1 and selecteditem and selectedvalue is set to null , and combobox doesn't show the selection of the field


    but if i change the line into

    <ComboBox x:Name="FieldComboBox" Grid.Column="0" ItemsSource="{Binding Fields}" SelectedItem="{Binding Field,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

    and use the regular wpf combobox it will work


    it only happens when it's loaded , after it's loaded if i change stuff , it will work , but the first time doesn't work


    how can i solved this?

    thanks
  2. George
    Admin
    George avatar
    1332 posts

    Posted 05 Jan 2011 Link to this post

    Hello,

    I tried to reproduce the problem, but to no avail. Attached you can find the sample. For the second RadComboBox the selected item is an object Field with Name = "Name 4"

    All the best,
    George
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for WPF
  3. UI for WPF is Visual Studio 2017 Ready
  4. igal a
    igal a avatar
    28 posts
    Member since:
    Oct 2009

    Posted 06 Jan 2011 Link to this post

    i solved it ,
    i implemented Equals and GetHashCode on the field class
    and it worked

    probably it compared different instances
  5. Ronny
    Ronny avatar
    8 posts
    Member since:
    Mar 2012

    Posted 10 Jul 2012 Link to this post

    Hey igal,

    I have the same issue here with a telerik combobox. Can you please explain your solution in detail. Didn't really get it...Thx in advance.

    Ronny
  6. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 13 Jul 2012 Link to this post

    Hello Ronny,

    I guess he used Equals method in order to compare the objects by their properties and in this way to ensure that SelectedValue will be set correctly.

    The next code snipped represents a sample Equals() method:

    public override bool Equals(object obj)
    {
        var field = obj as Field;
     
        if (field != null)
            return field.Name == this.Name;
        else
            return base.Equals(obj);
    }


    Greetings,
    Vladi
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
UI for WPF is Visual Studio 2017 Ready