Unplanned
Last Updated: 24 Sep 2020 13:27 by ADMIN
Martin Ivanov
Created on: 24 Sep 2020 13:27
Category: ComboBox
Type: Bug Report
5
ComboBox: Text get cleared when an item was previously selected and the control loses focus with an invalid text

According to the following article, when the UpdateSelectionOnLostFocus property is set to True and you enter a text that cannot update the selection, once the control loses the focus, the typed text should stay in the textbox. 
https://docs.telerik.com/devtools/wpf/controls/radcombobox/howto/perform-selection-only-lost-focus

However, this doesn't happen if an item is already selected. In this case, the searched text is cleared. If you do not have a selection, then the text stays on lost focus. 

To work this around, you can cache the value of the RadComboBox's Text property in the PreviewLostKeyboardFocus event handler and then restore it in the LostFocus event handler. 

private string textCache;
private void RadComboBox_PreviewLostKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e)
{
	this.textCache = this.comboBox.Text;
}
private void RadComboBox_LostFocus(object sender, RoutedEventArgs e)
{
	this.comboBox.Text = this.textCache;
}

0 comments