PreviewLostKeyboardFocus gets fired even when the focus enters the editable combobox.

1 posts, 0 answers
  1. Mausami
    Mausami avatar
    29 posts
    Member since:
    May 2011

    Posted 15 Nov 2011 Link to this post

    Hello Telerik team,

    When a user enters a value in the editable textbox of the RadCombobox that doesn't matches any of the available list of items then though the selected value is set to null , the text remains in the editable textbox even on lost focus of the RadCombobox.

    I have a requirement where I have to perform a validation when the user tabs out of the editable RadCombobox or tries to click on a different control. The validation is to verify if the text entered by the user is available in the list of items and if not then alert the user of this and open the dropdown.

    I implemented this validation on PreviewLostKeyboardFocus event as given below. But the problem is this event gets fired even when the focus enters the RadCombobox.

    After the Ok button of the alert is clicked and then when I try to click of the dropdown's button, this event gets fired again and so the alert.

    Why does this event fires when the focus enters the radcombobox.

    Could you please guide me.

    private void radCmbCustomer_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
                if ((sender as RadComboBox) != null
                    && ((sender as RadComboBox).ItemsSource as Customer[]) != null)
                    Customer[] larrCustomer = ((sender as RadComboBox).ItemsSource as Customer[]);
                    /*Check if the code entered by the user*/
                    TextBox txtEditableTextBoxRadCmbCustomer = radCmbCustomer.Template.FindName("PART_EditableTextBox", radCmbCustomer) as TextBox;
                    if (txtEditableTextBoxRadCmbCustomer != null)
                        string lstrCustomer = txtEditableTextBoxRadCmbCustomer.Text;
                        if (lstrCustomer != null && !lstrCustomer.Trim().Equals(string.Empty))
                            var lvarCustomerRecordsMatched = from lobjCustomer in larrCustomer
                                                            where lobjCustomer.CustomerName.ToUpper() == lstrCustomer.ToUpper()
                                                            select lobjCustomer;
                            if (lvarCustomerRecordsMatched != null && lvarCustomerRecordsMatched.ToList<Customer>().Count <= 0)
                                MessageBox.Show("The text you entered isn't an item in the list. \nSelect an item from the list, or enter text that matches one of the listed items.", "Alert");
                                radCmbCustomer.IsDropDownOpen = true;
                                e.Handled = true;


Back to Top