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

SelectedItem not in ItemsSource

8 Answers 265 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
MiddleTommy
Top achievements
Rank 1
MiddleTommy asked on 24 Jan 2012, 08:56 PM
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.

8 Answers, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 27 Jan 2012, 10:37 AM
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 >>
0
MiddleTommy
Top achievements
Rank 1
answered on 27 Jan 2012, 02:43 PM
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
0
Jonathan
Top achievements
Rank 1
answered on 28 Jan 2012, 01:45 AM
I agree this behavior would be much more preferable.

As a workaround I have had to build a conditional binding markup extension.
0
Konstantina
Telerik team
answered on 01 Feb 2012, 10:51 AM
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 >>
0
MiddleTommy
Top achievements
Rank 1
answered on 01 Feb 2012, 02:17 PM
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.
0
Konstantina
Telerik team
answered on 06 Feb 2012, 12:00 PM
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 >>
0
Scott
Top achievements
Rank 1
answered on 14 Nov 2014, 10:53 AM
I'm wondering if this has been fixed yet and if so what version was this done?
0
Kalin
Telerik team
answered on 18 Nov 2014, 11:49 AM
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.

 
Tags
ComboBox
Asked by
MiddleTommy
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
MiddleTommy
Top achievements
Rank 1
Jonathan
Top achievements
Rank 1
Scott
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or