I have a ListBox with binding to a list of strings. I want to filter the list when I enter text in a TextBox. How can I do it?
publ
If you set Dictionary as itemsource to listbox use the below code to sort,
private void tb_filter_textChanged(object sender, TextChangedEventArgs e)
{
Dictionary dictObject = new Dictionary();
ICollectionView view = CollectionViewSource.GetDefaultView(dictObject);
view.Filter = CustomerFilter;
listboxname.ItemsSource = view;
}
private bool CustomerFilter(object item)
{
KeyValuePair Items = (KeyValuePair) item;
return Items.Value.ToString().Contains("a");
}
The above code returns the items contaning "a".