Hey. Help to implement a strict / non-strict search in the DataGridView , as in the screenshot: Datagrid filter

Auto-fill code:

 var dataSet = new DataSet(); dataSet.ReadXml("file.xml"); dataGridView1.DataSource = dataSet.Tables["offer"]; 

So far implemented so. To manual filling has not yet reached.

  • show the code that fills the DataGrid with data - PashaPash
  • supplemented the question with the code filling in the datagrid - Andrei

1 answer 1

For DataTable Grid View displays the DefaultView — which has a property to filter on — with support for basic SQL syntax:

 private void textBox1_TextChanged(object sender, EventArgs e) { (dataGridView1.DataSource as DataTable).DefaultView.RowFilter = String.Format("Country like '{0}%'", textBox1.Text); } 
  • Well, you are geniuses! Everything is working. And at first I neighing over the error "there was no column" Country ")) - Andrei
  • And in order not to reload xml somehow you can reset the search phrase, for example, on another button? - Andrei
  • @ Andrew, you can - write in the handler click on this button textBox1.Text = "" - PashaPash
  • it's a little wrong, it just clears the textbox, and does not return all the xml strings)) Well, okay with that. I noticed that the implemented search is looking for consistently entered words: an example of "mom washed the frame", but would not find the "soap frame mom." How to implement a search without regard to the word order? but? )) and there I'll try to make the switch of these two searches myself - Andrei
  • @Andrey, you should take a textbook on SQL and read about SELECT. as well as the answer to how to search without word order lies on the surface String.Format("Country like '%{0}%'", textBox1.Text); - Dmitry