我已搜查,但似乎无法找到我所要完成更改单个细胞的基于细胞的DataGrid中值的颜色
的解决方案,我有一个dataGridView2和我想的细胞如果单个单元格中的值不为空,则Superfrom列将变为红色
我已搜查,但似乎无法找到我所要完成更改单个细胞的基于细胞的DataGrid中值的颜色
的解决方案,我有一个dataGridView2和我想的细胞如果单个单元格中的值不为空,则Superfrom列将变为红色
我假设您使用的是WinForms,并且您的列名为Superfrom。
foreach (DataGridViewRow row in dataGridView2.Rows)
{
DataGridViewCell cell = row.Cells[Superfrom.Index];
if (cell.Value != null)
cell.Style.BackColor = Color.Red;
else
cell.Style.BackColor = Color.White;
}
您对空白的定义可能会有所不同。在这种情况下,用任何陈述将为您的空虚情况测试替换cell.Value != null
。
foreach (DataGridViewRow row in dataGridView2.Rows)
{
DataGridViewCell cell = row.Cells[Superfrom.Index];
if (cell.Value.ToString() != String.Empty)
{
cell.Style.BackColor = Color.Red;
}
else
{
cell.Style.BackColor = Color.White;
}
}
您是否尝试过CellPainting事件 – PLED 2013-05-04 19:48:25