CellFormatting事件绑定判断
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;
}
}
}
如果当前表格的第三列的值是1的话 就显示经理,是0的话 就显示员工
private void dgvList_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex==2)
{
if (Convert.ToInt32(e.Value) == 1)
{
e.Value = "经理";
}
else
{
e.Value = "员工";
}
}
}