CellFormatting事件绑定判断

时间:2022-03-07 14:46:40
private void dataGridView1_CellFormatting( object sender, DataGridViewCellFormattingEventArgs e)
{
   
if (e.ColumnIndex == 1 /* status列的Index */ )
    {
       
if ( object .Equals(e.Value, 0 ))
        {
            e.Value
= " 未完成 " ;
            e.CellStyle.ForeColor
= Color.Red;
        }
       
else
        {
            e.Value
= " 已完成 " ;
            e.CellStyle.ForeColor
= Color.Green;
        }
    }
}