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

RadCombobox: prevent “Backspace” button from clearing selected item.

1 Answer 292 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andrii
Top achievements
Rank 1
Andrii asked on 10 Feb 2012, 08:39 AM

It seems that default behavior of RadCombobox is to clear selected item when control is focused, some item is selected  and “Backspace” button is pressed. 

I need to cancel this behavior in order to prevent setting of null as the selected combobox value. I tried to override KeyDown and KeyUp methods of RadCombobox and handle the click on “Backspace” but it did not fix the problem.

Are there any other ways to change this keyboard behavior?

Regards,

Andrii

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 Feb 2012, 11:20 AM
Hello Andrii,

Try the following code to prevent "Backspace" button from clearing the text.
C#:
public MainPage()
{
   InitializeComponent();
   RadComboBox1.AddHandler(KeyDownEvent, new KeyEventHandler(RadComboBox1_KeyDown), true);
}
   string combotxt;
   private void RadComboBox1_KeyDown(object sender, KeyEventArgs e)
    {
        if(e.Key==Key.Back)
          {
             if (RadComboBox1.SelectedItem == null)
               {
                   RadComboBox1.EmptyText = combotxt;
               }
         }
    }
 
        private void RadComboBox1_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
        {
            combotxt = RadComboBox1.Text;
        }

Thanks,
Princy.
Tags
ComboBox
Asked by
Andrii
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or