Hello I am trying to find unique strings in two dataGridView tables populated from XML files. The code I have made runs without issue however it fails to detect when I change a string (making it unique) in one of the tables. Is there anything wrong with my logic?
private void button5_Click(object sender, EventArgs e)
{
string[] column1 = new string[dataGridView1.Rows.Count];
string[] column2 = new string[dataGridView2.Rows.Count];
int unique = 0;
bool found = false;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
column1[i] = Convert.ToString(dataGridView1.Rows[i].Cells[2].Value);
}
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
column2[i] = Convert.ToString(dataGridView2.Rows[i].Cells[2].Value);
}
for (int i = 0; i < column1.Length; i++)
{
for (int j = 0; j < column2.Length; j++)
{
if (column1[i] == column2[j])
{
found = true;
}
}
if (found == false)
{
unique++;
found = false;
}
}
MessageBox.Show(unique + " unique strings found!");
}
The final solution needs to be able to return the cells that contain unique strings so that I can highlight them to the user. Thanks a lot for your help!