I have a BindingList list and a ComboBox dropdownUI.
If I do: dropdownUI.DataSource = list, all the employees in the list will show in the drop down. I want to know if there is a way to only show the employees that have hidden = false so when I modify the employee hidden attribute, I can hide the record from the combo box?
public class Employee {
public string name {get; set;}
public bool hidden {get; set;}
public Employee(string name, bool hidden) {
this.name = name;
this.hidden = hidden;
}
}
There is no way using the
BindingListitself. It implements theIBindingListinterface but you need theIBindingListViewinterface to get filtering. You have three main options:IBindingListView.DataTablewith the data and either bind that directly or bind it via aBindingSource. When you bind aDataTable, the data actually comes from itsDefaultView, which is typeDataView. BothDataViewandBindingSourceimplementIBindingListView.The first two options would allow you to modify an item and have the filter automatically update the UI, while the third option would require you to generate a new filtered list every time you modify an item.