Arpit Khandelwal
Arpit Khandelwal

Reputation: 1803

Combobox filter text lost when I type the latest inputs with some delay

I need this WPF ComboBox as a dropdown where user cannot enter text like textbox but still be able to search via typing text.

I set IsEditable = false and IsTextSearchEnabled = true and it works.

But the problem is that lets say a user is searching for text "Japan". User start text input into the combo with "J". Some items starting with "J" appear in the filtered list of the drop down panel. Now if user waits for 3-4 seconds and then types "a" (to complete typing "Japan"), the filtered list will rather move to items starting with "a".

It should rather search for "Ja" but it searches for "a" and discards "J".

Any ideas how do I fix this behavior?

Upvotes: 3

Views: 1010

Answers (1)

RandomActsOfCode
RandomActsOfCode

Reputation: 3285

In short, I don't think you can (easily). See this post:

WPF combobox search item

What it boils down to is that internally ComboBox is using a built-in class called TextSearch. In this class the timeout interval is hard-coded and is not publicly accessible, so you can not change this behaviour.

However, you might have some luck by implementing your own control that inherits from ComboBox and provides an override of the protected members OnTextInput and OnKeyDown. In here, you could implement your own searching logic and own timeout (which could be exposed as a DependencyProperty and hence configurable from within XAML).

Upvotes: 2

Related Questions