Selectable null value in RadComboBox

5 posts, 0 answers
  1. Rudis
    Rudis avatar
    30 posts
    Member since:
    Feb 2010

    Posted 16 Jun 2010 Link to this post

    I want to have null as an option in a Combobox, but I can´t figure out how to do that. I´m using MVVM and adds a null value at index 0 to my bounded IList : regioner.Insert(0, null);

    Nothing crashes but the user can´t choose the null item.

    Best regards / Anna
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 21 Jun 2010 Link to this post

    Hi Anna Rudlund,

    You could set ClearSelectionButtonVisibility to Visible and ClearSelectionButtonContent to the content that will be shown in this button. Then when the user click on this button the selected item will be null.
    There is no need to add NULL item in your data source.

    Let us know if you need more information.

    Kind regards,
    Hristo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Rudis
    Rudis avatar
    30 posts
    Member since:
    Feb 2010

    Posted 21 Jun 2010 Link to this post

    Thanx!

    That works perfekt! Just was I was looking for.

    Best regards / Anna
  5. Inger Marie
    Inger Marie avatar
    60 posts
    Member since:
    Nov 2010

    Posted 20 Jan 2015 in reply to Hristo Link to this post

    "Then when the user click on this button the selected item will be null."

    Is there a way to change the selected item from being set to null to some other value ? I have several scenarios where that would be great, mainly concerning non-nullable values such as enumerations (and numbers/int) and structs.
  6. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 23 Jan 2015 Link to this post

    Hello Inger,

    The behavior of the ClearButton could not be changed or modified. However, what we could suggest you in order to achieve the desired is to bind the SelectedIndex property of RadComboBox to the ViewModel. If the currently selected index is -1 (that value is set when the ClearButton is pressed) you could implement you're own custom logic and set it to some other value:
    public int SelectedIndex
    {
        get
        {
            return this.selectedIndex;
        }
        set
        {
            if(this.selectedIndex != value)
            {
                if(value == -1)
                {
                    //Implement your custom logic here. For example when the ClearButton is pressed the SelectedIndex will be set to 2
                    this.selectedIndex = 2;
                }
                else
                {
                    this.selectedIndex = value;
                }
                this.OnPropertyChanged(() => this.SelectedIndex);
            }
        }
    }

    Hopes this helps.

    Regards,
    Nasko
    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
UI for WPF is Visual Studio 2017 Ready