It is required to go through the DataGridView and find there certain data entered from the textbox. How to implement it?

I tried it, it turned out but the error "The link to the object does not indicate an instance of the object." Crashes on the line in if.

for (int i = 0; i < dataGridView1.RowCount; i++) { if (dataGridView1.Rows[i].Cells[0].Value.ToString() == textBox1.Text.ToString() && dataGridView1.Rows[i].Cells[1].Value.ToString() == textBox2.Text.ToString()) { MessageBox.Show("Здарова"); } } 
  • corrected the question. check turned out, but gives an error - Paul Greengod
  • There is a canonical question about this error. In short, it means that some of the objects used are null. Check which one. I assume that this is one of the Value (write if I am right or wrong). - default locale
  • In order to figure out which of the objects is null, divide each expression into parts and check them one by one in debug mode. Or look at the “Chain” example in response to a canonical question . - default locale
  • @defaultlocale really DGV had empty cells, but at the moment I removed them, but the error remained. - Paul Greengod
  • Well, why build hypotheses if you can simply see what exactly returns null when an error occurs in debug mode. There you will see what kind of cell it is and what is wrong with it. - default locale

0