Setting SelectedItem On Editable RadComboBox Does Not Work

4 posts, 1 answers
  1. Beijerinc
    Beijerinc avatar
    19 posts
    Member since:
    Feb 2011

    Posted 01 Feb 2012 Link to this post

    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

  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 03 Feb 2012 Link to this post

    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 >>

  3. DevCraft banner
  4. Beijerinc
    Beijerinc avatar
    19 posts
    Member since:
    Feb 2011

    Posted 03 Feb 2012 Link to this post

    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
  5. Answer
    Yana
    Admin
    Yana avatar
    4554 posts

    Posted 08 Feb 2012 Link to this post

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