过滤数据源,其中列喜欢/包含 VB.NET
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31164125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Filter datasource where column like/contains VB.NET
提问by Callum Holden
UPDATE
更新
Thanks to Hanlet the problem is solved, the syntax is like so:
感谢 Hanlet 问题解决了,语法是这样的:
source1.Filter = "[Column] LIKE '%" & TextBox1.Text & "%'"
Also for anyone interested, this is the syntax for performing the above on multiple criteria:
同样对于任何感兴趣的人,这是在多个条件上执行上述操作的语法:
source1.Filter = "[Column1] LIKE '%" & TextBox1.Text & "%' OR [Column2] LIKE '%" & TextBox1.Text & "%'"
I currently have code to filter my datasource where the column 'Customer Name' equals the text in the text box.
我目前有代码来过滤我的数据源,其中“客户名称”列等于文本框中的文本。
However, what I want is a filter that is similar to the LIKE function in sql, so if the customer name is 'John' and the user inputs 'Jo' into the text box, it will filter all customers who's name is LIKE/contains 'Jo'
但是,我想要的是一个类似于sql中的LIKE函数的过滤器,所以如果客户名称是'John'并且用户在文本框中输入'Jo',它将过滤所有名称为LIKE/contains的客户'乔'
This is the current filter code (if you want the code showing how the data is bound just ask):
这是当前的过滤器代码(如果您想要显示数据如何绑定的代码,请询问):
Dim source1 As New BindingSource()
source1.Filter = "[Customer Name] = '" & TextBox1.Text & "'"
dTableMain.Refresh()
Thanks for any help!
谢谢你的帮助!
回答by JustADude
I've done something similar in the past. Here's the general syntax:
我过去做过类似的事情。这是一般语法:
' The searchString is searched for in both the Cost Center field AND the Code field
BindingSource.Filter = "[col1] like " & searchString & " OR [col2] like " & searchString
In your case, it would be:
在您的情况下,它将是:
source1.Filter = "[Customer Name] like " & TextBox1.Text
Hope it helps!
希望能帮助到你!

