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

Text cleared when the focus-out without selection.

1 Answer 109 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Gongdo
Top achievements
Rank 1
Gongdo asked on 27 May 2013, 02:40 PM
Hi guys,

On your ComboBox Configurator example; http://demos.telerik.com/silverlight/#ComboBox/Configurator
  1. set the TextSearchMode to Contains.
  2. typed some text that is not contained in ItemsSource, say 'extra'. 
  3. pressed the 'Tab' key in order to escape the focus of the ComboBox.
Then, the Text 'extra' that I've typed is cleared.

It seems like kind of 'designed' behavior, however when you set the TextSearchMode to StartsWith and try instructions above, then you could see the Text 'extra' remained. Isn't it weird?

I think the Text should be remained until the user clears the text explicitly.

Can I get a work-around so that I can perform additional process with unexpected user-inputted-text?

- gongdo

1 Answer, 1 is accepted

Sort by
0
Accepted
Vladi
Telerik team
answered on 30 May 2013, 08:43 AM
Hi,

By design the when an item is not selected in the control on LostFocus the input text is cleared in both TextSearchModes. The issue that could be reproduced in the online example seems to be caused by the example itself as we couldn't reproduce it in a sample project. If you want the non existing input text to be saved to the control you will need to implement it with the use of the KeyUp and LostFocus events.

The next code snippet shows how to reset the input text to the ComboBox when the focus is lost:
in the xaml:
<telerik:RadComboBox LostFocus="RadComboBox_LostFocus_1"
            KeyUp="RadComboBox_KeyUp_1"/>
and in the code behind:
private string inputText;
 
private void RadComboBox_LostFocus_1(object sender, RoutedEventArgs e)
{
    var comboBox = sender as RadComboBox;
    comboBox.Text = inputText;
    inputText = null;
}
 
private void RadComboBox_KeyUp_1(object sender, KeyEventArgs e)
{
    var comboBox = sender as RadComboBox;
 
    this.inputText = comboBox.Text;
}

Hope this is helpful.

Regards,
Vladi
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ComboBox
Asked by
Gongdo
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Share this question
or