我从excel表中读取并为BindingList编写了以下内容,在Form_Load()中,它被设置为DataSource作为BindingSource:
bd = new BindingSource(); //instance of BindingSource
bd.DataSource = ExcelOPS.LerExcel(); //LerExcel() method return a BindingList<T>
gvFiltro.DataSource = bd; //set a DataGridView named gvFiltro DataSource property
bindNav.BindingSource = bd; //set a BindingNavigator source这很好用!我打算为这个DataGridView gvFiltro创建一个组合框作为过滤器,所以在combobox的SelectedIndexChanged事件中,我尝试如下:
this.gvFiltro.DataSource = null;
bd.Filter = string.Format("TAG_FAZENDA like '%{0}%'", cbTagFaz.Text);
gvFiltro.DataSource = bd;
gvFiltro.Update();
gvFiltro.Refresh();
bindNav.BindingSource = bd;
bindNav.Update();
bindNav.Refresh();但DataGridView并没有改变。我错过了什么吗?
发布于 2016-02-22 19:53:20
不能使用Filter属性筛选其DataSource设置为BindingList<T>的BindingSource。
只有实现
IBindingListView接口的底层列表支持筛选。
您可以使用Linq过滤BindingList<T>:
var filteredBindingList= new BindingList<T>(bindingList.Where(x=>some criteria).ToList());然后可以使用筛选绑定列表作为数据源。
发布于 2016-02-22 17:57:23
你可以试试:
bd.resetBindings(false)祝好运
更新
我会尝试这样的方法:
bd.Filter = string.Format("TAG_FAZENDA like '%{0}%'", cbTagFaz.Text);
gvFiltro.resetbindings(false)
gvFiltro.Update();
bindNav.resetbindings(false)
bindNav.Update();就这个。
https://stackoverflow.com/questions/35560365
复制相似问题