两个问题:
你将如何合并这两段代码?将它们分成两个大块似乎有点多余!
您将如何通过多列进行搜索(如果在以下列中的任何一列中找到结果,则返回结果:姓名、性别、年龄)?
private void button1_Click(object sender, EventArgs e) { BindingSource bs = new BindingSource(); bs.DataSource = dataGridView1.DataSource; bs.Filter = "id like '%" + textBox1.Text + "%'"; dataGridView1.DataSource = bs; } private void textBox1_TextChanged(object sender, EventArgs e) { BindingSource bs = new BindingSource(); bs.DataSource = dataGridView1.DataSource; bs.Filter = "id like '%" + textBox1.Text + "%'"; dataGridView1.DataSource = bs; }