您的位置:首页 > 其它

dataGridView绑定泛型的筛选功能实现

2011-04-12 09:51 316 查看
一次筛选

IList<Model> list = (IList<Model>)dataGridView2.DataSource;

var query = from student in list

//where student.FormCode.StartsWith(textBox3.Text.Trim())
where student.FormCode.Contains(textBox3.Text.Trim())
//where student.FormCode.EndsWith(textBox3.Text.Trim())

select student;
dataGridView2.DataSource = new LocalDataer.BindingCollection<Model>(query.ToList());

真正的仿绑定DataTable实现

var query = from student in listsouse

//where student.FormCode.StartsWith(textBox3.Text.Trim())
where student.FormCode.Contains(textBox3.Text.Trim())
//where student.FormCode.EndsWith(textBox3.Text.Trim())

select student;
dataGridView2.DataSource = new LocalDataer.BindingCollection<Model>(query.ToList());

这里的listsouse是一个不变的泛型集合,采用的是Linq查询,大家可以随意修改可实现不同效果,如果好的方法也请通知我,谢谢
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: