1
votes

I have followed the following links to create a custom combo box. I have added a list of combo box items using c#.

If I type text in the custom combo box it is not filtering the items based on the search text whether an item contains the word.

The custom combo box just listing all the items in it. I want my combo box to act like if type word it should filter the result and auto-suggest in the combo box search.

<local:FilteredComboBox x:Name="FilteredCmb"  IsEditable="True"
            IsTextSearchEnabled="True" 
            Padding="4 3" 
            MinWidth="200" Grid.ColumnSpan="6" 
            Grid.Column="2" Margin="0,77,0,49" Grid.Row="1" />

How to achieve this?

Is this possible with a Default combo box. The default combo box auto-suggests the items which start with the entered text not with checking whether the word is contained in an item.

Create Custom ComboBox1 Custom ComboBox2

1
Naveen, please provide us a mcve to help you. Nandri.Mathivanan KP
you may need a 3rd party lib for that...Jazb
Really you'e looking at a custom control, people commonly refer to it as the AutoCompleteTextBox.user8478480

1 Answers

0
votes

I have used combo box key up event to filter the result.

<local:FilteredComboBox x:Name="FilteredCmb"  IsEditable="True" 
IsTextSearchEnabled="False" **KeyUp="FilteredCmb_KeyUp"** Padding="4 3" MinWidth="200" 
Grid.ColumnSpan="6" Grid.Column="2" Margin="0,77,0,49" Grid.Row="1" />

C# Code

private void FilteredCmb_KeyUp(object sender, KeyEventArgs e)
{
    List<BoxItem> filteredItems = new List<BoxItem>();

    for (int i = 0; i < cmbItems.Count; i++)
    {
        string currentItem = cmbItems[i].Text.ToLower();

        // get the text in the editable combo box 
        string typedText = FilteredCmb.Text.ToLower();

        if (currentItem.Contains(typedText))
        {
            filteredItems.Add(cmbItems[i]);
        }

    }

// Clear the combo box before adding new items to Combo Box

    foreach(BoxItem item in filteredItems)
    {
        FilteredCmb.Items.Add(item);
    }

    FilteredCmb.IsDropDownOpen = true;
}