Articles in this section
Category / Section

How to filter dropdown items in WPF editable ComboBoxAdv?

2 mins read

This article describes how to filter dropdown items in a WPF editable ComboBoxAdv.

We can obtain the ComboBoxAdv text using the ComboBoxAdv.KeyUp event.

XAML

MainWindow.xaml

<Grid>
    <syncfusion:ComboBoxAdv x:Name="comboBoxAdv" HorizontalAlignment="Center" VerticalAlignment="Center" Width="200" Height="25" ItemsSource="{Binding List}" DisplayMemberPath="Name" IsEditable="True">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="KeyUp">
                <local:FilterAction/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </syncfusion:ComboBoxAdv>
</Grid>

In the below code, we filter the ComboBoxAdv collectionview itemsource based on the obtained ComboBoxAdv text.

C#
FilterAction.cs

public class FilterAction : TargetedTriggerAction<ComboBoxAdv>
{
    protected override void Invoke(object parameter)
    {
        CollectionView items = (CollectionView)CollectionViewSource.GetDefaultView(Target.ItemsSource);
        items.Filter = ((o) =>
        {
            if (String.IsNullOrEmpty(Target.Text))
                return true;
            else
            {
                if ((o as Model).Name.Contains(Target.Text))
                    return true;
                else
                    return false;
            }
        });
        items.Refresh();
    }
}

The output for the above code is shown below.

output

View sample in GitHub

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied