我如何在数据网格中过滤超过 1 列

How can i filter more than 1 column at datagrid

我使用此工作代码从文本框中搜索任何部分单词,但只是 在一列内 (名字)和 return DataGridView 内的过滤结果:

  ContactsTableBindingSource.Filter = String.Format("{0} LIKE '%{1}%'", "Firstname", TextBox1.Text)

如何在其他列中搜索??我试过一些这样的代码:

  ContactsTableBindingSource.Filter = String.Format("{0} LIKE '%{1}%'", "Firstname" OR ContactsTableBindingSource.Filter = String.Format("{0} LIKE '%{1}%'", "Lastname", TextBox1.Text)

  ContactsTableBindingSource.Filter = String.Format("{0} LIKE '%{1}%'", "Firstname" OR "Lastname", TextBox1.Text)

但是不行! 谁能告诉我在任何列搜索 任何部分单词 的正确语法是什么?

您的语法不正确。 Filter 属性 内部实际上允许使用布尔表达式。示例:

String.Format("{0} LIKE '%{2}%' OR {1} LIKE '%{2}%'", "Firstname", "Lastname", TextBox1.Text)