效果:
代码:
/// <summary>
/// 格式化数据
/// </summary>
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 3 ) //哪一列
{
if (Convert.ToInt32(e.Value) == 1)
{
e.Value="存在维修记录,双击查看!";
e.CellStyle.ForeColor = Color.Green;
}
else if(Convert.ToInt32(e.Value) == 0)
{
e.Value="未创建维修记录!";
e.CellStyle.ForeColor = Color.Red;
}
else { }
}
}