【发布时间】:2019-09-27 08:52:46
【问题描述】:
我在 Windows 窗体中使用 dataGridView 来显示数据库并希望为它着色。如果 [Solver] 列为 NULL,它应该绘制 LightSalmon,否则绘制 LightGreen。但是,即使列值为 NULL,它仍然会将其视为非 null 并绘制成 LightGreen。
This is my table:
[Id]
[Employee]
[Section]
[Machine]
[Station]
[MachNo]
[Area]
[Type]
[Desc]
[Recommendation]
[Date]
[Solver]
[Process]
public void Color()
{
for(int i = 0; i< dataGridView1.Rows.Count; i++)
if (DBNull.Value.Equals(dataGridView1.Rows[11]))
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.LightSalmon;
}
else
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.LightGreen;
}
}
【问题讨论】:
-
GRidView.Column 数据类型与 DBNull 不同
-
也尝试实现
dataGridView1.Refresh()。