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

Disabling Backspace Clear

2 Answers 117 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 16 Nov 2012, 12:53 PM
I'd like to disable the ability of the backspace key to clear my RadComboBox. I have tried doing the following:

public MyPage()
{
    InitializeComponent();
 
    this.myCombo.AddHandler(FrameworkElement.KeyDownEvent, new KeyEventHandler(myCombo_KeyDown), true);
}
 
protected void myCombo_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Back)
    {
        e.Handled = true;
    }
}

But this doesn't appear to work due to the fact that myCombo is cleared before my event handler ever fires, and e.Handled is already set to true. 

Is there any way I can disable the current backspace functionality?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Ventzi
Telerik team
answered on 21 Nov 2012, 12:16 PM
Hi Andrew,

Unfortunately there is no way to handle the BackSpace key in Silverlight. The main reason is because you cannot handle the system key events in the TextBox which is a template child of the RadComboBox. 

In WPF you could handle the PreviewKeyDown event to prevent the backspace.

All the best,
Ventzi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Paul
Top achievements
Rank 1
answered on 02 May 2013, 10:07 AM
Hi,
    The limitation of not being able to disable the backspace key suck but understand why based on what you have said. Anyway a workaround for it is.
private void cboSite_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
{
    if (cboSite.SelectedItem == null) {
        if (e.RemovedItems.Count > 0) { cboSite.SelectedItem = e.RemovedItems[0]; }
    }
}

This stops the backspace key deleting the current selected item.

Thanks
Tags
ComboBox
Asked by
Andrew
Top achievements
Rank 1
Answers by
Ventzi
Telerik team
Paul
Top achievements
Rank 1
Share this question
or