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

Backspace clears the ComboBox SelectedItem

6 Answers 846 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 24 Jul 2013, 09:17 PM
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?

6 Answers, 1 is accepted

Sort by
0
Rosen Vladimirov
Telerik team
answered on 29 Jul 2013, 10:58 AM
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 >>
0
Deepak
Top achievements
Rank 1
answered on 01 Dec 2013, 09:28 AM
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
0
Vladi
Telerik team
answered on 04 Dec 2013, 08:24 AM
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 >>
0
Matt
Top achievements
Rank 1
answered on 17 Jan 2014, 04:54 PM
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.
0
Rosen Vladimirov
Telerik team
answered on 22 Jan 2014, 03:23 PM
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 >>
0
Dilyan Traykov
Telerik team
answered on 29 Oct 2019, 11:47 AM

Hello,

Another possible approach for handling this scenario is to create a custom FilteringBehavior in which to prevent the SelectedItem from becoming null:

    public class CustomFilteringBehavior : ComboBoxFilteringBehavior
    {
        public override List<int> FindMatchingIndexes(string text)
        {
            var indexes = base.FindMatchingIndexes(text);

            return indexes.Count == 0 ? new List<int>() { this.ComboBox.SelectedIndex } : indexes;
        }
    }

The behavior can then be set like so:
            <telerik:RadComboBox.FilteringBehavior>
                <local:CustomFilteringBehavior />
            </telerik:RadComboBox.FilteringBehavior>

Regards,
Dilyan Traykov
Progress Telerik

Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
ComboBox
Asked by
Matt
Top achievements
Rank 1
Answers by
Rosen Vladimirov
Telerik team
Deepak
Top achievements
Rank 1
Vladi
Telerik team
Matt
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or