日期:2014-05-17  浏览次数:20768 次

请问,DataGridView如何这样改变单元格颜色?
DataGridView绑定到datatable
如何使DataGridView随着datatable数据的变化,使得有数据的单元格颜色是红色,没有值(null)的单元格是默认的白色
谢谢!!

------解决方案--------------------
CellFormatting事件,设置e.CellStyle.xxxx
C# code

        private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.Value.ToString() == "yes")
            {
                e.CellStyle.ForeColor = Color.Red;
            }
        }

------解决方案--------------------
楼上正解!