こんにちは、XML ファイルから入力された 2 つの dataGridView テーブルで一意の文字列を見つけようとしています。私が作成したコードは問題なく実行されますが、テーブルの 1 つで文字列を変更 (一意にする) すると検出に失敗します。私の論理に何か問題がありますか?
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!");
}
最終的な解決策では、一意の文字列を含むセルを返して、それらをユーザーに強調表示できるようにする必要があります。助けてくれてどうもありがとう!