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

RadComboBox IsEditable=True with repeated value in DisplayMemberPath

5 Answers 111 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
joao rodrigues
Top achievements
Rank 1
joao rodrigues asked on 04 Jan 2011, 06:39 PM

Hi, I've a list of items bound to a RadCombo with IsEditable set to true. Two items of that list had the same name (DisplayMemberPath). When the second (in this case last) item is selected in Combobox, the first one becames the selected item. The real problem is much more complex than this example but the unexpected behaviour is the one that is reported in this post.
public class Person
{
    public string Name { get; set; }
}
public partial class MainPage : UserControl, INotifyPropertyChanged
{
    public List<Person> Crowd {get;set;}
    private Person _SelectedPerson;
    public Person SelectedPerson
    {
        get { return _SelectedPerson; }
        set
        {
            _SelectedPerson = value;
            NotifyOfPropertyChange("SelectedPerson");
        }
    }
    public MainPage()
    {
        InitializeComponent();
        Crowd = new List<Person>();
        Crowd.Add(new Person { Name = "Sam" });
        Crowd.Add(new Person { Name = "Mary" });
        Crowd.Add(new Person { Name = "Wendy" });
        Crowd.Add(new Person { Name = "Steven" });
        Crowd.Add(new Person { Name = "Sam" });
        this.DataContext = this;
        SelectedPerson = Crowd[0];
    }
    public event PropertyChangedEventHandler PropertyChanged;
    public void NotifyOfPropertyChange(string propname)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propname));
        }
    }
}
<UserControl x:Class="RadComboBoxTest.MainPage"
    mc:Ignorable="d">
    <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel Orientation="Vertical">
            <ListBox ItemsSource="{Binding Crowd}" SelectedItem="{Binding SelectedPerson, Mode=TwoWay}" Width="200">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <telerik:RadComboBox SelectedItem="{Binding Path=SelectedPerson, Mode=TwoWay}"
                                 ItemsSource="{Binding Path=Crowd}"
                                 DisplayMemberPath="Name"
                                 IsEditable="True" Width="200"/>
        </StackPanel>
    </Grid>
</UserControl>
Can you help me on that ? Thanks.

5 Answers, 1 is accepted

Sort by
0
Michael Lilly
Top achievements
Rank 1
answered on 06 Jan 2011, 07:20 PM
I am having this exact same problem.  So any solution that can be given would be great.

Apparently when you select the second item in the list, it populates the text box which then forces the first item to be selected.  Then if you select the second item a second time, it will be the one selected.  But that first selection needs to stay.

My scenerio:

City selection combo box, with a combination of city and state in the actual drop down but only the city name shown as the display member.  I have two cities, Charleston, WV and Charleston, SC.  You select the second item (say the WV version), the SelectionChanged event gets hit twice, the second time is for the SC version.

Any fix or workaround would be greatly appreciated.
0
Konstantina
Telerik team
answered on 07 Jan 2011, 11:09 AM
Hello,

This is the way that the ComboBox is working. To avoid this, you have to make sure that there are no duplicate items in the ItemsSource.

Please let us know if you have any other questions regarding our controls.

Kind regards,
Konstantina
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
joao rodrigues
Top achievements
Rank 1
answered on 07 Jan 2011, 11:34 AM
Hello,

Thanks for your feedback.

Well, maybe it is the way that combo is working but is not the correct way. I'm not typing anything in combo, all I'm doing is changing the (bound) selecteditem and the selecteditem in combo is not the selected item i've selected.

You said that duplicated items in itemsource must be avoided. Well, I don't have duplicated items in itemsource only items with same "DisplayMemberPath" property value, in my case the "description", and that field can be anything since is user defined so the "workaround" is not valid.

Of course I cold complement the description with some kind of extra value to ensure the uniqueness  but this would be a big trick and as I'm not a magician I don't like tricks in my work very much. 

Regards,
Joao

0
Michael Lilly
Top achievements
Rank 1
answered on 07 Jan 2011, 03:04 PM
I have to agree with Joao, I don't have duplicate items in my itemssource, only duplicate display names.  If the user selects an item in the drop down, that should be the one that stays selected.  It makes no sense to reselect something that the user didn't select.  Granted, if they type in Charleston from my example, I expect the first item to be selected, but no, they physically selected the second item, that's what should stay selected.

This is clearly a bug, why would you select a different item than what the user selected, no matter what is in the itemssource?
0
Valeri Hristov
Telerik team
answered on 07 Jan 2011, 03:26 PM
This is a known limitation that we will try to workaround in the near future. I cannot promise a solution for the upcoming service packs, as it will require a lot of changes in RadComboBox, it is possible however, that we will update the control with Q1 2011 in March.

In the beginning of February there will be a public beta, you could try it to see if it works for your scenario.

All the best,
Valeri Hristov
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
ComboBox
Asked by
joao rodrigues
Top achievements
Rank 1
Answers by
Michael Lilly
Top achievements
Rank 1
Konstantina
Telerik team
joao rodrigues
Top achievements
Rank 1
Valeri Hristov
Telerik team
Share this question
or