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

Setting SelectedItem On Editable RadComboBox Does Not Work

3 Answers 204 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Beijerinc
Top achievements
Rank 1
Beijerinc asked on 01 Feb 2012, 12:28 PM
Hello,

I want to use the RadComboBox to display a set of options. The user should be able to "create" his own option by typing in the ComboBox. To achieve this, I have declared the RadComboBox as such:
<telerikinput:RadComboBox
   SelectedItem="Z" ItemsSource="{Binding Items}"
   IsEditable="True" TextSearchMode="StartsWith"
   CanAutocompleteSelectItems="True" CanKeyboardNavigationSelectItems="True" />

The Items collection is an ObservableCollection<string>, containing "A", "B" and "C". What I want, is that the ComboBox text is set to Z upon startup. The user can pick "A", "B" or "C" from the list, or he can edit "Z".

Why is the ComboBox blank upon startup? I have also tried the SelectedValue property, but that did not work either. How can I get the desired behavior?

Kind regards,
Beijerinc

3 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 03 Feb 2012, 01:10 PM
Hello Rick,

The SelectedItem property should be set to an object from the ItemsSource collection. In your case you can bind "Text" property.

Regards,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Beijerinc
Top achievements
Rank 1
answered on 03 Feb 2012, 01:37 PM
Hello Yana,

Thank you, I seemed to have overlooked that property. For the purpose of databinding though, it would be best to have a uniform way of setting the selected item. I would expect that if I set a non-predefined value in the SelectedItem property of an editable ComboBox, it would simply set that custom value as the selected item. For instance, what if I want to set a custom value that is not simply text?

In my current scenario, I have a list with values (this will become the ItemsSource) and the current value (from a datasource). I want to set the SelectedItem to the current value, but since the ComboBox is editable, it should allow items that are not predefined. I do not want to "choose" if I have to set the SelectedItem or the Text property, as I do not have access to the code behind in this scenario (dynamic "Templated Control" with a Style Selector).

Can I solve this scenario with the RadComboBox?

Kind regards,
Beijerinc
0
Accepted
Yana
Telerik team
answered on 08 Feb 2012, 01:05 PM
Hi Rick,

I am afraid that this is the expected behavior of RadComboBox. In your case you can bind both Text and SelectedItem to properties in the ViewModel.

We are sorry for any inconvenience caused.

Kind regards,
Yana
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
ComboBox
Asked by
Beijerinc
Top achievements
Rank 1
Answers by
Yana
Telerik team
Beijerinc
Top achievements
Rank 1
Share this question
or