我正在从多个源(csv文件,..)数据读取数据到数组,然后通过foreach(){.Add(..)}读取到DatagridView。
现在,我希望可以通过用户输入的文本字段在控件中搜索数据。
这可能是我制作DataTable而不是在C#中创建数组或类似GenericList<T>
的最佳方法吗?
答案 0 :(得分:1)
您可以使用数据表
DataTable table = new DataTable();
BindingSource bs = new BindingSource();
使用BindingSource绑定数据表
dataGridView1.DataSource = bs;
bs.DataSource = table;
过滤记录
bs.Filter= string.Format("column LIKE '%{0}%'", value);
为什么不列出?
列表未实现IBindingList
,因此网格不知道您的新项目。
为什么不绑定列表?
您不能使用Filter
属性来过滤其数据源设置为BindingSource
的{{1}}。
如何使用自定义对象?
您可以创建扩展的BindingList<T>
(Refer this)。