public class CatalogueEntry
{
private string _code;
private string _desc;
public CatalogueEntry(string code, string desc)
{
_code = code;
_desc = desc;
}
public string Code => _code;
public string Description => _desc;
}
目录列表(使用BindingList):
public class Catalogue : BindingList<CatalogueEntry>
{
}
初始化:
_catalogue = new Catalogue();
_catalogue.Add(new CatalogueEntry("BAGG", "It scares us all"));
_catalogue.Add(new CatalogueEntry("BIGG", "It embiggens us all"));
_catalogue.Add(new CatalogueEntry("BOGG", "It demeans us all"));
_catalogue.Add(new CatalogueEntry("BUGG", "It frightens us all"));
_source = new BindingSource();
_source.DataSource = _catalogue;
dataGridView.DataSource = _source;
我得到了上述数据的一个很好的网格。
var filter = "Description like 'scares'";
_source.Filter = filter;
什么都没有发生,即过滤器似乎不工作。我该怎么做才能让过滤器工作?
我猜底层数据源不是一个数据库,所以不会理解“像‘恐慌’一样的描述”。
编辑:如果我按以下方式更改过滤器:
var text = "scares";
var list = _catalogue.Where(entry => entry.Description.Contains(text));
_source.DataSource = list;