Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > ComboBox > PreviewLostKeyboardFocus gets fired even when the focus enters the editable combobox.

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

Feed from this thread
  • Mausami avatar

    Posted on Nov 15, 2011 (permalink)

    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;
                                txtEditableTextBoxRadCmbCustomer.Focus();
                                e.Handled = true;
                                return; 
                 }
                        }
                    }
                }


    Thanks,
    Regards,
    Mausami


    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > ComboBox > PreviewLostKeyboardFocus gets fired even when the focus enters the editable combobox.
Related resources for "PreviewLostKeyboardFocus gets fired even when the focus enters the editable combobox."

WPF ComboBox Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]