绑定源在DataGridView C#中有两个或多个单词的列名称不起作用 [英] Binding Source doesn't work on column names with two or more words in DataGridView C#

查看:217
本文介绍了绑定源在DataGridView C#中有两个或多个单词的列名称不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用BindingSource.Filter来过滤datagridview上的数据。我使用以下代码:

I am using BindingSource.Filter to filter data on my datagridview. I used the following code:

BindingSource bs = new BindingSource();
bs.DataSource = datagridview1.DataSource;
bs.Filter = "columnName like '%" + textBox1.Text + "%'";
datagridview1.DataSource = bs;

此代码可以正常工作。但是当我在两个字的列中过滤数据时,代码不再工作。我尝试将这些单词放在code'列名称'像'%'+ tbFilter.Text +%'之类的单词上,但这并没有帮助。请帮助我找到正确的代码来过滤我的列中的数据。

This code works. But when I filter data on a two-word column, the code does not work anymore. I tried putting apostrophe on those words like 'column name' like '%" + tbFilter.Text + "%', but this does not help. Please help me find the right code to filter data on my columns.

推荐答案

]

bs.Filter = "[column Name] like '%" + textBox1.Text + "%'";

我认为即使您的列名称是单字,总是一个好主意。

I think it's always a good idea even if your column names are one-word.

这篇关于绑定源在DataGridView C#中有两个或多个单词的列名称不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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