2 つのグリッドビューがあり、列ごとに結果を比較する必要があります。グリッドビューの 1 つに、他のグリッドビューにはない列がある場合があるため、両方のグリッドに存在する列のみを比較する必要があります。
私が書いたコードは、実際には各行のすべてのセルを通過し、行0セル0から始まり、行0セル1を続け、次の行に進みます。ただし、たとえばグリッド 2 の列がグリッド 1 に存在する場合、そのセルを通過してから次の列に渡すようにセルを作成したいと思います。以下は私が持っているコードです:
List<String> columnsGrid43 = new List<String>();
foreach (TableCell cell in gridReport43.Rows[0].Cells)
{
BoundField fieldGrid43 = (BoundField)((DataControlFieldCell)cell).ContainingField;
columnsGrid43.Add(fieldGrid43.DataField);
}
foreach (TableCell cell in gridReport44.Rows[0].Cells)
{
BoundField fieldReportGrid44 = (BoundField)((DataControlFieldCell)cell).ContainingField;
if (columnsGrid43.Contains(fieldReportGrid44.DataField))
{
for (int countRow = 0; countRow < gridReport44.Rows.Count; countRow++)
{
for (int countCell = 0; countCell < gridReport44.Rows[countRow].Cells.Count; countCell++)
{
string grid1Value = gridReport43.Rows[countRow].Cells[countCell].Text;
string grid2Value = gridReport44.Rows[countRow].Cells[countCell].Text;
if (grid2Value.Contains(grid1Value))
{
gridReport43.Rows[countRow].Cells[countCell].BackColor = Color.FromArgb(101, 226, 75);
gridReport44.Rows[countRow].Cells[countCell].BackColor = Color.FromArgb(101, 226, 75);
}
else
{
gridReport43.Rows[countRow].Cells[countCell].BackColor = Color.FromArgb(255, 102, 102);
gridReport44.Rows[countRow].Cells[countCell].BackColor = Color.FromArgb(255, 102, 102);
}
}
}
}
}