天天看點

dataGridView綁定泛型的篩選功能實作

一次篩選

            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())

這裡的listsouse是一個不變的泛型集合,采用的是Linq查詢,大家可以随意修改可實作不同效果,如果好的方法也請通知我,謝謝

繼續閱讀