DataGridView Filter a BindingSource with a List of object as DataSource

后端 未结 3 1368
长发绾君心
长发绾君心 2020-12-14 03:23

I\'m trying to filter a BindingSource with a BindingList as Datasource. I tried BindingSource.Filter = \'Text Condition\' But it didn\'t work, nothing happens, the data on s

3条回答
  •  眼角桃花
    2020-12-14 03:55

    As per http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.filter.aspx

    Only underlying lists that implement the IBindingListView interface support filtering.

    BindingList does not appear to implement IBindingListView - and since it is the underlying list, your collection will not filter.

    BindingSource class, while not generic, does implement this Interface, so try using this as your personas collection. I get the feeling that simply assigning a new BindingSource's datasource to a BindingList won't suffice, since it doesn't change the underlying list. Try:

    BindingSource personas = new BindingSource { new Person{ ... }, ... };
    

提交回复
热议问题