SelectedItem not in ItemsSource

9 posts, 0 answers
  1. MiddleTommy
    MiddleTommy avatar
    163 posts
    Member since:
    Nov 2009

    Posted 24 Jan 2012 Link to this post

    Is it possible to have the SelectedItem of the Combobox be set and display correctly even if the item is not in the ItemsSource. I have had several scenarios where this would be usefull.
  2. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 27 Jan 2012 Link to this post

    Hello Tommy,

    I am afraid this is not possible with the current implementation of the ComboBox. If you share your scenario in details with us, we might be able to suggest you a better approach for achieving this, if possible.

    All the best,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. DevCraft banner
  4. MiddleTommy
    MiddleTommy avatar
    163 posts
    Member since:
    Nov 2009

    Posted 27 Jan 2012 Link to this post

    I just read that Silverlight 5 adds similar behavior

    http://msdn.microsoft.com/en-us/library/hh397894(v=VS.95).aspx 
    "Prior to Silverlight 5, if you set the SelectedIndexSelectedItem, or SelectedValue before setting a Selector's ItemsSource, that value would be coerced to null. In Silverlight 5, the values stay set so there is selection when the ItemsSource is set. This enables a number of binding scenarios and matches the behavior in WPF. "

    I set the RadCombobox ItemsSource async. So it would be nice to have the RadComboBox follow this behavior. But actually show the value.

    Also I have scenarios where I am binding multiple sources to the same CurrentItem. But the combobox does not always have the current item
  5. Jonathan
    Jonathan avatar
    37 posts
    Member since:
    Jul 2012

    Posted 27 Jan 2012 Link to this post

    I agree this behavior would be much more preferable.

    As a workaround I have had to build a conditional binding markup extension.
  6. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 01 Feb 2012 Link to this post

    Hello,

    The issue with the ComboBox is the following: when the ItemsSource is set, before all items are loaded, the SelectedValue will work only the first time, i.e. if the first item is not the searched one it will stop the search:

    var items = new ObservableCollection<DataItem>();
    combo.ItemsSource = items;
    foreach (var item in result)
    {
         items.Add(item);

    In order to make it work, it has to be set like this:

    var items = new ObservableCollection<DataItem>();
    foreach (var item in result)
    {
        items.Add(item);
    combo.ItemsSource = items;

    We are aware of this issue. However, we are still looking for a way to fix this without breaking the entire logic of the ComboBox and consequently all clients' project.

    Hope this information helps.

    Regards,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  7. MiddleTommy
    MiddleTommy avatar
    163 posts
    Member since:
    Nov 2009

    Posted 01 Feb 2012 Link to this post

    It would also be much appreciated to add this behavior as well.

    var items = new ObservableCollection<DataItem>();
    items.Add(itemA);
    items.Add(itemB);
    items.Add(itemC);
    combo.ItemsSource = items;
    combo.SelectedItem = itemE;//Selected item will be shown as itemE but itemE will not be in the drop down.
  8. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 06 Feb 2012 Link to this post

    Hi Tommy,

    I tested this behaviour with the ComboBox from the Toolkit, but seems that this behaviour is not available there also. So, I suppose once this is implemented there, we will be able to include it in RadComboBox as well.

    Regards,
    Konstantina
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  9. Scott
    Scott avatar
    3 posts
    Member since:
    Feb 2012

    Posted 14 Nov 2014 in reply to Konstantina Link to this post

    I'm wondering if this has been fixed yet and if so what version was this done?
  10. Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 18 Nov 2014 Link to this post

    Hi Scott,

    I'm afraid it is not possible to set the SelectedItem to an item that is not present in the ItemsSource. However if this does not answer your question, I'll ask you to open another thread and explain the exact issue there as this is really old thread and already contains few different discussions.

    Regards,
    Kalin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
DevCraft banner