Category / Section
How to filter dropdown items in WPF editable ComboBoxAdv?
1 min read
This article describes how to filter dropdown items in WPF editable ComboBoxAdv.
To obtain the ComboBoxAdv text using 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 to filter the ComboBoxAdv collectionview itemsource based on 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