首页 > 解决方案 > 如何比较两个DatagridView的两列

问题描述

我有 2DatagridView并且我有相同的列datagridView1dataGridView2现在我想比较1 和 2Column [ID]中的每一行datagridView,如果ID存在于 2 列中,Column["Names"]传递到.["Age"]datagridView2dataGridView1

这只是我有,但它没有显示。

for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
    for (int a = 0; a < dataGridView2.Rows.Count; a++)
    {
        if (dataGridView1.Rows[i].Cells[0].Value == dataGridView2.Rows[i].Cells[0].Value)
        {
            dataGridView1.Rows[i].Cells[2].Value = dataGridView2.Rows[a].Cells[2].Value.ToString();
            dataGridView1.Rows[i].Cells[3].Value = dataGridView2.Rows[a].Cells[3].Value.ToString();

            i++;
            a++;
        }
    }
}

标签: c#winformsdatagridview

解决方案


推荐阅读