Search code examples
c#.netwpfwpf-controlswpfdatagrid

How to change dropdown items in combobox with change of text?


I am working on POS using EPF C#. To add saleline items I want to use combobox and want to change selection for its dropdown with the change of text in combobox to search? How can I change combox list items with Textchanged property or any other way? And Can I also use datagrid columns or datagrid for this purpose?


Solution

  • After reading your comments it appears you want a textbox that is able to filter a list of items. My suggestion would be to subscribe to the textboxes "textchanged" event.

    textbox.TextChanged += Textbox_TextChanged;
    

    Then do the filtering in the method that you used to subscribe to the event with

    private void Textbox_TextChanged(object sender, TextChangedEventArgs e)
    {
        //do list sorting here ex.)
        List<string> FilteredResults = SomeList<string>.where(i => i.Contains(textbox.text)).ToList();
    }
    

    This will get you a filtered list of items (strings in this case) that you can then display in the ComboBox.

    Note: The MVVM design pattern makes this extremely simple and clean to pull off.