RadComboBox IsEditable=True with repeated value in DisplayMemberPath

6 posts, 0 answers
  1. joao rodrigues
    joao rodrigues avatar
    20 posts
    Member since:
    Mar 2010

    Posted 04 Jan 2011 Link to this post


    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.
  2. Michael Lilly
    Michael Lilly avatar
    53 posts
    Member since:
    Apr 2010

    Posted 06 Jan 2011 Link to this post

    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.
  3. DevCraft banner
  4. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 07 Jan 2011 Link to this post

    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
  5. joao rodrigues
    joao rodrigues avatar
    20 posts
    Member since:
    Mar 2010

    Posted 07 Jan 2011 Link to this post

    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

  6. Michael Lilly
    Michael Lilly avatar
    53 posts
    Member since:
    Apr 2010

    Posted 07 Jan 2011 Link to this post

    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?
  7. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 07 Jan 2011 Link to this post

    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
Back to Top
DevCraft banner