Is it possible to filter the contents of a Listbox in a Windows Forms application?
The DataSource of my ListBox is a BindingSource containing a bunch of DTOs in an:
IList<DisplayDTO>
I want to filter on the DTO property that is specified in the ListBox’s DisplayMember.
The text to be filtered on is provided in a separate Text Box.
This should work :
EDIT: this works only if the underlying data source (
bindingSource.DataSource) implementsIBindingListView. In the FCL, only theDataViewclass implements this interface.You can create your own implementation by inheriting from
BindingList<T>. Here’s an article that explains how to add the filter functionality. You can also find various implementations ofSortableBindingListon Google.