Combobox element for WPF auto search

In WPF, when I type text into the combobox, it will highlight the element starting with the text I entered. This highlight will search for all text that I have entered in the combo box. But instead, I want the text search to only match the first letter. How to do it?

Sample code to re-create the problem:

XAML:

<Window x:Class="ComboTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
  <StackPanel>
    <ComboBox x:Name="cb"></ComboBox>
  </StackPanel>
</Window>

      

Code for:

 namespace ComboTest
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            cb.Items.Add("a");
            cb.Items.Add("ab");
            cb.Items.Add("abc");
            cb.Items.Add("agsf");
            cb.Items.Add("b1");
            cb.Items.Add("b2");
            cb.Items.Add("b3");
            cb.Items.Add("b4");
            cb.Items.Add("bbb");
            cb.Items.Add("bbbbb");
            cb.Items.Add("c4");
            cb.Items.Add("c");
            cb.Items.Add("c1");
            cb.Items.Add("c2");
            cb.Items.Add("cbb");
            cb.Items.Add("cbd");
            cb.Items.Add("d");
            cb.Items.Add("de");
            cb.Items.Add("df");

        }
    }
}

      

Now run this solution, click on the combo box to open the popup and click continuously so that it goes around all items starting with a symbol. I need similar behavior when we continuously press "B".

+2


source to share


1 answer


There's a great article by Ioan Lazarchuk at http://www.lazarciuc.ro/ioan/2008/06/01/auto-complete-for-textboxes-in-wpf/ that you could use to simulate combo autocomplete.



In your specific case, you will need to change the private void Suggest () method to find the first letter.

+1


source







All Articles