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

RadComboBox Selection from Binding Problems

4 Answers 301 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
igal a
Top achievements
Rank 1
igal a asked on 30 Dec 2010, 03:25 PM
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

4 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 05 Jan 2011, 09:37 AM
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
0
igal a
Top achievements
Rank 1
answered on 06 Jan 2011, 05:16 PM
i solved it ,
i implemented Equals and GetHashCode on the field class
and it worked

probably it compared different instances
0
Ronny
Top achievements
Rank 1
answered on 10 Jul 2012, 06:15 AM
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
0
Vladi
Telerik team
answered on 13 Jul 2012, 12:12 PM
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 >>

Tags
ComboBox
Asked by
igal a
Top achievements
Rank 1
Answers by
George
Telerik team
igal a
Top achievements
Rank 1
Ronny
Top achievements
Rank 1
Vladi
Telerik team
Share this question
or