Autocomplete for ComboBox in WPF anywhere in the text (not only at the beginning)

I have a ComboBox in WPF that I worked a lot with (it has its own template and custom element template). I have everything until the moment when it works pretty much the way I want it, except that when I enter the ComboBox it performs filtering for me, but only filters that assume that I print start the element name in a ComboBox.

For example, if I have an item in ComboBox called “Windows Media Player”, it will only find it if I start typing “Windows Media ...” and it won’t find it if I start typing “Media Play” “...” Is there a way around this? Can I set the property somewhere so that it can look for it in the entire string, and not just use StartsWith ()?

If not, what would be the best way to do this yourself? Is there a way to take the original control and basically just change the call from StartsWith () to the call to Contains (), or will I have to go much lower level?

+29
c # wpf combobox
Feb 06 '09 at 22:34
source share
6 answers

Check out the article below in CodeProject: WPF TextBox Multi-User Autocomplete

+8
Dec 30 '09 at 20:25
source share

Combobox now supports autocomplete, just make sure in xaml for combobox put

IsEditable="True" 
+38
Nov 30 '11 at 10:21
source share

As far as I know, there is no way to make the standard ComboBox behave this way by simply changing the setting. Thus, you will have to implement your own derived code for this or look for a ready-made third-party control (I think there are many of them).

+4
Feb 09 '09 at 8:45
source share

You can try to process ComboBox TextInput or PreviewTextInput events, search for the text yourself, select the most suitable element and set "e.Handled = true". Just a thought. Hope this helps!

edit:

This works for a single character (i.e. if you enter the letter "j", it will select the first element that contains "j" or "J"), but I'm sure there is a way to do this using your control. Enjoy it!

 private void MyComboBox_PreviewTextInput(object sender, TextCompositionEventArgs e) { foreach (ComboBoxItem i in MyComboBox.Items) { if (i.Content.ToString().ToUpper().Contains(e.Text.ToUpper())) { MyComboBox.SelectedItem = i; break; } } e.Handled = true; } 
+4
Feb 18 '09 at 3:06
source share

WPF component does not support autocomplete

Here is an example that allows you to do this indirectly by applying a filter to the elements.

See http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/cec1b222-2849-4a54-bcf2-03041efcf304/

+2
Feb 18 '09 at 7:58
source share

I think this may help. You can change the filter to your needs. By default, it searches by matching the contents of the string, but you can easily change the condition to StartsWith if you need to ...

https://gist.github.com/mariodivece/0bbade976aea8d416d52

0
Oct 30 '15 at 2:33
source share



All Articles