我有两个datagridview。 具有相同的列标题但不同的单元格数据。用c中的不同值突出显示datagridview的单元格#
第一个叫grid_db 第二个是calld grid_statement。
如果grid_db的值与cell [j]上的grid_statement的值不同,我必须使单元格高亮显示(红色)。 我尝试以下
int no_of_col = grid_db.Columns.Count;
int j;
for (j = 0; j < no_of_col;)
{
//if statement value is null replace with ZERO
if (grid_statement.Rows[0].Cells[j].Value != null &&
!string.IsNullOrWhiteSpace(grid_statement.Rows[0].Cells[j].Value.ToString()))
{
B = grid_statement.Rows[0].Cells[j].Value.ToString();
}
//if db value is null replace with zero
if (grid_db.Rows[0].Cells[j].Value != null &&
!string.IsNullOrWhiteSpace(grid_db.Rows[0].Cells[j].Value.ToString()))
{
A = grid_db.Rows[0].Cells[j].Value.ToString();
}
if (A != B)
{
grid_db.Rows[0].Cells[j].Style.BackColor = Color.Red;
grid_statement.Rows[0].Cells[j].Style.BackColor = Color.Red;
j++;
}
}
不过,这并不works.The上面的代码突出了网格的所有列。 帮助?
它适合你吗?这只是他的代码的简化变体。我尝试了他和你的代码,但我仍然无法给这些单元格着色。我找不到原因。 –
bahh ..没有任何结果。他的代码也将所有单元格绘成红色。 –