我有一个来自数据集的填充网格视图;我想检查 Column[4] 单元格(标题除外),如果它的单元格值小于 0 ,则背景变为红色。
请帮助...非常感谢
这是一个适用于 Windows 窗体的示例。
dataGridView1.Rows.Add(3, 2, -3);
dataGridView1.Rows.Add(1, -2, 3);
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (!row.IsNewRow && int.Parse(row.Cells[2].Value.ToString()) < 0)
row.Cells[2].Style.BackColor = Color.Red;
}
根据需要进入 commonHeaderCellStyle 属性。