读书人

请教DataGridView怎么这样改变单元格

发布时间: 2012-10-16 09:57:37 作者: rapoo

请问,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;            }        }
[解决办法]
楼上正解!

读书人网 >C#

热点推荐