如何将bindingsource过滤器重置为无 [英] How to reset bindingsource filter to nothing

查看:1001
本文介绍了如何将bindingsource过滤器重置为无的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在LINQ to SQL中使用 BindingSource ,并在我的项目中实现了 BindingList Textbox 用于过滤 DataGridView 中的行,因此当我删除文本框内容时,Filter应该重置为无。 / p>

我的代码如下:

  if(textBox1.Text。 Length == 0)
{
productBindingSource.Filter = null;
}
else
{
productBindingSource.Filter =ProductName ='+ textBox1.Text +';
//productBindingSource.RemoveFilter();
}
productDataGridView.DataSource = productBindingSource;

但是这没什么,任何想法呢?

解决方案

尝试如下:

  if(textBox1.Text.Length == 0){
productBindingSource.RemoveFilter();
} else {
productBindingSource.Filter =ProductName ='+ textBox1.Text +';
}

// productDataGridView.DataSource = productBindingSource;

如果DataGridView已经使用productBindingSource,则不需要再次使用DataSource。


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 DataGridView, so when I delete the textbox content, Filter should be reset to nothing.

My code is as follows:

if (textBox1.Text.Length == 0)
{
    productBindingSource.Filter = null;
}
else
{
    productBindingSource.Filter = "ProductName = '" + textBox1.Text +"'";
    //productBindingSource.RemoveFilter();
}
productDataGridView.DataSource = productBindingSource;

But this does nothing, any idea, please?

解决方案

Try it like this:

if (textBox1.Text.Length == 0) {
  productBindingSource.RemoveFilter();
} else {
  productBindingSource.Filter = "ProductName = '" + textBox1.Text +"'";
}

// productDataGridView.DataSource = productBindingSource;

The DataGridView shouldn't need to be DataSourced again if it's already using productBindingSource.

这篇关于如何将bindingsource过滤器重置为无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆