I have a List<T>
which is bound to a DataGridView like this:
BindingSource bs = new BindingSource();
bs.DataSource = list;
myDataGridView.DataSource = bs;
开发者_JS百科I want to filter the rows that are displayed using a predicate. How do I achieve this?
Many thanks
The simple solution be following:
Func<T, bool> predicate = ...; // Func<T, bool> or Predicate<T>
BindingSource bs = new BindingSource();
bs.DataSource = list.Where(x => predicate(x));
myDataGridView.DataSource = bs;
If your predicate changes then either refresh the data source or just re-assign it using the new predicate.
精彩评论