Auto Complete Box - SelectedItem not getting selected when typing or pasting then clicking off the control.

1 Answer 284 Views
AutoCompleteBox
James
Top achievements
Rank 1
James asked on 13 Jan 2022, 04:11 PM

I've noticed in the Auto Complete Box if you type a selection (or paste) and then left mouse click off the control the Selected Item will not be populated.

If I type (or paste) a selection and hit the "tab" key it will select the item.

How can I select the item when the user left mouse clicks off the control?

I can easily duplicate this with the "Auto Complete Box | First Look" from the WPF Controls Example.

See the attached pics.

The first example I typed "Respect" into the autocomplete box for Best Music Hit.  I hit the Tab button and the data populated.

The second example I typed "Respect" into the autocomplete box for Best Music Hit.  I then left mouse clicked outside of that control and the data does not populate.

Please advise.

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 18 Jan 2022, 02:17 PM

Hello James,

Currently, this is the default behavior of the RadAutoCompleteBox control, which is to not select an item when the focus is changed (click outside) because the user has not picked a value. However, you could still achieve the wanted result by creating a new class that derives from the RadAutoCompleteBox class and then subscribing to its LostFocus event. In the event, you could use the protected HandleKeyDown event by passing the Key.Enter key as a parameter, which will select the highlighted item.

The following code snippet shows this approach's implementation:

public class CustomAutoCompleteBox : RadAutoCompleteBox
{
    public CustomAutoCompleteBox()
    {
        this.LostFocus += CustomAutoCompleteBox_LostFocus;
    }
 
    private void CustomAutoCompleteBox_LostFocus(object sender, System.Windows.RoutedEventArgs e)
    {
        this.HandleKeyDown(System.Windows.Input.Key.Enter);
    }
}

With that said, I have attached a sample project for you to test, so, could you give it a try?

Regards,
Stenly
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
AutoCompleteBox
Asked by
James
Top achievements
Rank 1
Answers by
Stenly
Telerik team
Share this question
or