Autocomplete combobox for WPF

autocomplete combobox wpf mvvm
wpf autocomplete
wpf autocomplete textbox dropdown
wpf autocomplete combobox toolkit
wpf toolkit
wpf combobox
syncfusion autocomplete wpf
wpf combobox istextsearchenabled

I need an autocomplete combobox for WPF C#. I've tried several approaches but nothing works. For example I've tried a combobox:

<ComboBox  Width="200"
      IsEditable="True"
      ItemsSource="{Binding Names}"
      IsTextSearchEnabled="True"
      HorizontalAlignment="Left"/>

Names is a List of Strings: Peter John, John, John Doe, Cathy, Howard, John Richards and so on

If you type in a name e.g. John the combobox should expand and I should see

  • John
  • John Doe
  • John Richards
  • Peter John

But that doesn't work. How can I do that?


After a lot of fiddling, I have managed to arrive at a complete, working solution. (Or so it seems.)

Step 1. Modify XAML markup

You need to modify your ComboBox like so:

<ComboBox
    ...
    IsTextSearchEnabled="False"
    ...
    PreviewTextInput="PreviewTextInput_EnhanceComboSearch"
    PreviewKeyUp="PreviewKeyUp_EnhanceComboSearch"
    DataObject.Pasting="Pasting_EnhanceComboSearch" />

ie. to disable default text search, and add events handlers that will take care of user adding, deleting and pasting text.

Step 2. Add a helper function that will get ComboBox's internal TextBox (because WPF)

In order for PreviewTextInput_EnhanceComboSearch and Pasting_EnhanceComboSearch to work at all, you will need to access your ComboBox's caret. Unfortunately, to do this, you need to traverse, er, visual tree (hat tip to Matt Hamilton). You can do that in an extension method, but I used a static one in my Page class:

public static T GetChildOfType<T>(DependencyObject depObj) where T : DependencyObject
{
    if (depObj == null) return null;

    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
    {
        var child = VisualTreeHelper.GetChild(depObj, i);

        var result = (child as T) ?? GetChildOfType<T>(child);
        if (result != null) return result;
    }
    return null;
}
Step 3. Implement event handlers

Please note I used

s => s.IndexOf(e.Text, StringComparison.InvariantCultureIgnoreCase) != -1 

which is equivalent to case-insensitive s => s.Contains(e.Text) check. Remember to change that part to suit your needs.

Step 3.a Trigger search on user typing inside ComboBox

When a PreviewTextInput handler is run, the .Text property inside the ComboBox contains the text from before it was modified. Therefore, we need to get ComboBox's internal TextBox using GetChildOfType method in order to obtain its caret, so we know where exactly was the typed character inserted.

private void PreviewTextInput_EnhanceComboSearch(object sender, TextCompositionEventArgs e)
{
    ComboBox cmb = (ComboBox)sender;

    cmb.IsDropDownOpen = true;

    if (!string.IsNullOrEmpty(cmb.Text))
    {
        string fullText = cmb.Text.Insert(GetChildOfType<TextBox>(cmb).CaretIndex, e.Text);
        cmb.ItemsSource = Names.Where(s => s.IndexOf(fullText, StringComparison.InvariantCultureIgnoreCase) != -1).ToList();
    }
    else if (!string.IsNullOrEmpty(e.Text))
    {
        cmb.ItemsSource = Names.Where(s => s.IndexOf(e.Text, StringComparison.InvariantCultureIgnoreCase) != -1).ToList();
    }
    else
    {
        cmb.ItemsSource = Names;
    }
}
Step 3.b Trigger search on user pasting into ComboBox

DataObject.Pasting handler behaves in a similar fashion to PreviewTextInput hanlder, so we need the caret again.

private void Pasting_EnhanceComboSearch(object sender, DataObjectPastingEventArgs e)
{
    ComboBox cmb = (ComboBox)sender;

    cmb.IsDropDownOpen = true;

    string pastedText = (string)e.DataObject.GetData(typeof(string));
    string fullText = cmb.Text.Insert(GetChildOfType<TextBox>(cmb).CaretIndex, pastedText);

    if (!string.IsNullOrEmpty(fullText))
    {
        cmb.ItemsSource = Names.Where(s => s.IndexOf(fullText, StringComparison.InvariantCultureIgnoreCase) != -1).ToList();
    }
    else
    {
        cmb.ItemsSource = Names;
    }
}
Step 3.c Trigger search on user deleting text inside ComboBox (and also pressing Space, because WPF)

This will trigger when the user depresses either Delete or Backspace.

And also Space, because Space is ignored by PreviewTextInput, so it would be difficult to filter out "John" from "John Doe" and "John Richards" in the example.

private void PreviewKeyUp_EnhanceComboSearch(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Back || e.Key == Key.Delete)
    {
        ComboBox cmb = (ComboBox)sender;

        cmb.IsDropDownOpen = true;

        if (!string.IsNullOrEmpty(cmb.Text))
        {
            cmb.ItemsSource = Names.Where(s => s.IndexOf(cmb.Text, StringComparison.InvariantCultureIgnoreCase) != -1).ToList();
        }
        else
        {
            cmb.ItemsSource = Names;
        }
    }
}

...and that should probably be enough.

Autocomplete combobox for WPF, RadComboBox has full autocomplete support - while you type into the input area, the combobox returns the relative match for the currently typed text. RadComboBox has full autocomplete support - while you type into the input area, the combobox returns the relative match for the currently typed text. The purpose of this tutorial is to show you how to configure the autocomplete feature. The following sections are included: RadComboBox populated with a list of strings


use PreviewTextInput event for do filter and show drop down like this:

private void ComboBox_TextInput_1(object sender, TextCompositionEventArgs e)
    {           
        cmbperson.IsDropDownOpen = true;
        cmbperson.ItemsSource = DataBase.Persons.Where(p => p.Name.Contains(e.Text)).ToList();
    }

WPF ComboBox | AutoComplete, The WPF AutoComplete or search textbox auto suggests users to select an item with built-in features such as multiple selection, history, and filtering. The WPF AutoComplete control provides a common AutoComplete text box to easily select values from a predefined list and adds the common AutoComplete paradigm to text boxes. The control is loaded with features to help you customize the behavior, look, and feel in many different ways.


I suggest you use a control made for auto complete instead of a combobox. Many companies offer such controls, this one is free and considered good.

WPF AutoComplete TextBox, AutoCompleteComboBox for WPF. NuGet version. Provides a lightweight combobox with filtering (auto-complete). Screenshot. View all of README.md  Step 3.c Trigger search on user deleting text inside ComboBox (and also pressing Space, because WPF) This will trigger when the user depresses either Delete or Backspace. And also Space, because Space is ignored by PreviewTextInput , so it would be difficult to filter out "John" from "John Doe" and "John Richards" in the example.


I created an autocomplete to WPF that could help you. Follow the link below to github: https://github.com/rhpontes/AutocompleteWpf

I hope it helps you.

vain0x/DotNetKit.Wpf.AutoCompleteComboBox , Here's my implementation of a WPF ComboBox that takes the traditional Text Search on prefix (via the IsTextSearchEnabled property) to the  ComboBox with filtering (auto-complete) for WPF. Contribute to vain0x/DotNetKit.Wpf.AutoCompleteComboBox development by creating an account on GitHub.


In XAML you should set IsEditable=True and add handler for PreviewKeyDown event:

private void ComboBox_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        var cmb = (ComboBox)sender;
        cmb.IsDropDownOpen = true;
        var textbox = cmb.Template.FindName("PART_EditableTextBox", cmb) as TextBox;
        cmb.ItemsSource = CurrentStorage.Organisations.Where(p => string.IsNullOrEmpty(cmb.Text) || p.Name.ToLower().Contains(textbox.Text.ToLower())).ToList();
    }

Auto-Complete Combobox in WPF ~ Arkesh Korat, FYI, there is nice auto-complete text box in WPF Toolkit (). Why don`t you use it? Auto-Complete Combobox in WPF 12:39 PM Arkesh Korat 6 comments Here's my implementation of a WPF ComboBox that takes the traditional Text Search on prefix (via the IsTextSearchEnabled property) to the next level.


Autocomplete Combobox in WPF, The WPF ComboBox lacks the auto-complete feature and in this article, we will develop our own WPF user control that behaves like the  A Reusable WPF Autocomplete TextBox came close, but I can't get it to work with more than one filter (more info here). WPF autocomplete textbox/combobox doesn't work for me because it inherits from UserControl, and thus doesn't support the DataTemplates I need (for showing/selecting the value of one property for an object with multiple properties).


WPF Auto-Complete Control, In this article, you will learn about AutoComplete TextBox in WPF. ASP.NET MVC 5 - Kendo UI - Working With MultiColumnComboBox Using EFJan 23, 2019. AutoSuggest and AutoComplete control in WPF. Kostadin Mitev. and the most natural way to implement those without using a ComboBox is to use an AutoSuggest


https://social.msdn.microsoft.com/Forums/vstudio/e, I have a combobox in which I want to turn off suggest-append mode of combobox. Instead I want suggest-only mode. In many questions users ask for turning autoComplete feature off and everywhere I got the same answer. i.e. set IsTextSearchEnabled to False. When IsTextSearchEnabled = True. When IsTextSearchEnabled = False. What I want is :