vb.net 用文本框VB过滤datagridview

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14703435/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 12:12:03  来源:igfitidea点击:

Filter datagridview with text box VB

vb.netformseventsdatagridviewtextbox

提问by Jaun Lloyd

I've created a form that contains a datagridview and I've attached a datasource, works well if I want to see every record but I only want it to show a certain persons view, I found some code that people claim works but when I run the program I get an syntax error...

我创建了一个包含 datagridview 的表单,并附加了一个数据源,如果我想查看每条记录,效果很好,但我只希望它显示某个人的视图,我发现了一些人们声称有效的代码,但是当我运行程序我得到一个语法错误...

Syntax error: Missing operand after 'number' operator.

语法错误:“数字”运算符后缺少操作数。

SO has helped me a lot in the past since I'm new to programming, and if I may ask can you guys help me one again?

自从我刚接触编程以来,SO 过去对我帮助很大,如果我可以问你们能再帮我一次吗?

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) _ 
                                  Handles TextBox1.TextChanged
    If TextBox1.TextLength > 0 Then
        frmReportMenu.ProjectBindingSource.Filter = _ 
                String.Format("Register number Like '%" & TextBox1.Text) & "%'"
    Else
        frmReportMenu.ProjectBindingSource.Filter = String.Empty
    End If
End Sub

I've created a button when the user clicks on the button a form appears with a textbox

当用户单击按钮时,我创建了一个按钮,一个带有文本框的表单出现

回答by bonCodigo

I assume the column name is what is giving you the error. As per my comment,

我假设列名是什么给你的错误。根据我的评论,

It shouldn't contain a space between Registerand Number. If it has a space then you have to wrapt the column name like this: [Register number]

它不应该在Register和之间包含空格Number。如果它有空格,那么你必须像这样包装列名:[Register number]

Try this please: String.Format("[Register number] Like '%" & TextBox1.Text) & "%'"

请试试这个: String.Format("[Register number] Like '%" & TextBox1.Text) & "%'"

回答by Flashbond

The right parenthesis should be here: String.Format("Register number Like '%" & TextBox1.Text & "%'")

右括号应该在这里: String.Format("Register number Like '%" & TextBox1.Text & "%'")

Not here: String.Format("Register number Like '%" & TextBox1.Text) & "%'"

不在这里: String.Format("Register number Like '%" & TextBox1.Text) & "%'"