There are two dataGridView 7 and 8 on the form.

In 7, data from excel is loaded as a table, in 8, the database is loaded from the server, and you need to go through a cycle of searching and finding the names from dgv7 to dgv8. If found, then dyes in dgv7 with a green color the cell itself with a match. it turned out to make only one cycle, which will run through and search for a rigid reference to the word. I tried it like this, it did not work out. As I understand it, you need two cycles, but how to make them?

for (int i = 0; i < dataGridView7.RowCount; i++) { if (Convert.ToBoolean(dataGridView7.Rows[i].Cells[1].Value.ToString() == dataGridView8.CurrentRow.Cells[0].Value.ToString())) { dataGridView7.Rows[i].Cells[1].Style.BackColor = Color.Green; } } 
  • (1) Why Convert.ToBoolean ? Do your comparisons return something else? (2) Why ToString before comparison? Well this is not PHP. (3) Why is the comparison at the UI code level? You should not work with strings, but with intelligent typed entities. - VladD

1 answer 1

Usually a sequential search on two grids is done like this.

 for (int i = 0; i < dataGridView1.RowCount-1; i++) { for (int j = 0; j < dataGridView2.RowCount-1; j++) { } }