Filter BindingSource when DataSource is a BindingList

后端 未结 2 1132
逝去的感伤
逝去的感伤 2020-12-19 20:00

I have read from a excel sheet and wrote this for a BindingList, in Form_Load this is set to a DataSource as BindingSource:

bd = new BindingSource(); //insta         


        
相关标签:
2条回答
  • 2020-12-19 20:42

    You can not use Filter property to filter a BindingSource which it's DataSource is set to a BindingList<T>.

    Only underlying lists that implement the IBindingListView interface support filtering.

    You can filter the BindingList<T> using Linq:

    var filteredBindingList= new BindingList<T>(bindingList.Where(x=>some criteria).ToList());
    

    Then you can use filtered binding list as data source.

    0 讨论(0)
  • 2020-12-19 20:58

    You may try it:

        bd.resetBindings(false)
    

    Good luck

    UPDATE

    I would try something like this:

        bd.Filter = string.Format("TAG_FAZENDA like '%{0}%'", cbTagFaz.Text);
        gvFiltro.resetbindings(false)
        gvFiltro.Update();
    
        bindNav.resetbindings(false)
        bindNav.Update();
    

    Just this.

    0 讨论(0)
提交回复
热议问题