How to reset bindingsource filter to nothing

前端 未结 4 446
半阙折子戏
半阙折子戏 2021-01-24 12:55

Using BindingSource on LINQ to SQL, and having implemented a BindingList in my project, I have to use a Textbox to filter rows in a

4条回答
  •  礼貌的吻别
    2021-01-24 13:26

    I found that "Find" method cannot be used directly with BindingList, but fortunately there is an alternative, using IEnumerable. After Implementing a BindingList in the project, I can filter a bound datagridview using the next code:

        private void button1_Click(object sender, EventArgs e)
        {
            var qry = (from p in dc.Products
                       select p).ToList();
            BindingList list = new BindingList(qry);
            IEnumerable selection = list.Where(m => m.ProductName.Contains(textBox1.Text) == true);
            productBindingSource.DataSource = selection;
        }
    

提交回复
热议问题