Backspace clears the ComboBox SelectedItem

6 posts, 0 answers
  1. Matt
    Matt avatar
    10 posts
    Member since:
    Mar 2011

    Posted 24 Jul 2013 Link to this post

    I have set the IsEditable property to False, so the user can only select values from the list. Why would the backspace key allow the user to remove the selection?

    I cannot find any way to prevent this behavior. In my opinion, this behavior would never be desirable, but at the very least there should be some way to turn it off.

    Should I submit an issue for this?
  2. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 29 Jul 2013 Link to this post

    Hello Matt,

    RadComboBox is designed to work this way when Backspace is used. In order to prevent the removing of selected item, you will have to handle SelectionChanged event:
    private void Combo_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
    {
        var comboBox = sender as RadComboBox;
     
        if (comboBox != null)
        {
            if (comboBox.SelectedItem == null && e.RemovedItems.Count > 0)
            {
                comboBox.SelectedItem = e.RemovedItems[0];
            }
        }
    }

    The idea here is to check if the SelectedItem is null (when you press Backspace on your Keyboard, the SelectedItem will be null) and if there was a previous selection (e.RemovedItems holds previously selected Items). In this scenario you can assume that the Backspace key is hit, so you can set the previously selected item as current. Unfortunately you cannot handle KeyDown or KeyUp event as they are coming too late (in Silverlight there aren't PreviewKeyDown and PreviewKeyUp events). 

    Hopefully this helps. Feel free to contact us in case you have any problems or concerns.

    Regards,
    Rosen Vladimirov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
  4. Deepak
    Deepak avatar
    9 posts
    Member since:
    Sep 2013

    Posted 01 Dec 2013 Link to this post

    Hi Rosen,

      I also faced same issue like Matt. I used a telerik radcombobox in my application, within this combobox i use CheckBoxes property as true. If i choose multiple items from combobox then header is updated but if i clear the header by backspace and go to other control or click on outside, then some times header is updated to EmptyMessage & some times header is updated to showing one field name but other fields are still checked.

    So my requirement is if a user remove header text by backspace we should restrict him otherwise after removing if user go outside of this control the header should update according to selected items. So please help me.

    Thanks
    Deepak
  5. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 04 Dec 2013 Link to this post

    Hello,

    In the current version of RadComboBox multi selection is not supported and there may be unexpected behaviors when implementing it. Adding the Editing feature to the custom multi selection control brings many issues that unfortunately cannot be workaround in the current version of the control.

    You could take a look at our RadAutoCompleteBox control that supports multi selection out of the box. You can also take a look at our SDK example that demonstrates how you could add a drop down button to the control in order to make it look and feel more like a ComboBox control. The example is available at our online SDK repository at GitHub here, you can download the entire repository as a zip file via this link.

    Regards,
    Vladi
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Matt
    Matt avatar
    10 posts
    Member since:
    Mar 2011

    Posted 17 Jan 2014 Link to this post

    Hi Rosen,

    Your suggested work around will not work for me.

    The ComboBox SelectedValue property is bound to a data object. When the backspace key clears the SelectedValue, the data object gets marked as dirty. Yes, I am able to recover the previously selected value using your suggested work around, but my data object is still marked as dirty.
  7. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 22 Jan 2014 Link to this post

    Hello Matt,

    In this case the best option is to create a custom class that inherits RadComboBox and override HandleKeyDown and OnKeyDown methods. If the key is Backspace you can handle the event and the item will not be cleared.

    I've prepared a sample project demonstrating this approach. Please give it a try and inform us in case you have any problems or concerns.

    Regards,
    Rosen Vladimirov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
DevCraft banner