在winform中,使用DataGridView时,想在某一列,值为“true”时,将这列颜色改变,并且将值也改变,需要用到如下方法:
Code
private void gdvData_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 8 ) //哪一列
{
if (object.Equals(e.Value, "true"))
{
e.Value="成功";
e.CellStyle.ForeColor = Color.Green;
}
else
{
e.Value="失败";
e.CellStyle.ForeColor = Color.Red;
}
}
}