码迷,mamicode.com
首页 > 其他好文 > 详细

DevGridControl单元格背景色和单元格文字颜色设置

时间:2015-04-15 17:09:46      阅读:682      评论:0      收藏:0      [点我收藏+]

标签:

1.拖一个gridControl控件在 窗体上

2.添加三列 分别是 BgColor,BgColor2 , FontColor  分别显示单元格颜色 单元格渐变颜色 单元格字体颜色


 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            List<object> list = new List<object>();
            list.Add(new { BgColor = 11, BgColor2 = 12, FontColor = 13 });
            list.Add(new { BgColor = 21, BgColor2 = 22, FontColor = 23 });
            list.Add(new { BgColor = 31, BgColor2 = 32, FontColor = 33 });
            gridControl1.DataSource = list;
        }
        private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            GridView View = sender as GridView;
            if (e.Column.FieldName == "BgColor")//设背景
            {
                //int pointID = (gridView1.GetRow(e.RowHandle) as object).BgColor;
                e.Appearance.BackColor = Color.Red;
            }
            else if (e.Column.FieldName == "BgColor2")//设渐变背景
            {
                //int pointID = (gridView1.GetRow(e.RowHandle) as object).BgColor;
                e.Appearance.BackColor = Color.Red;
                e.Appearance.BackColor2 = Color.FromArgb(255, 255, 255);
            }
            else if (e.Column.FieldName == "FontColor")//设字体颜色
            {
                //int pointID = (gridView1.GetRow(e.RowHandle) as object).BgColor;
                e.Appearance.ForeColor = Color.Red;//Color.FromArgb(42, 173, 231);
            }
        }
    }

技术分享

DevGridControl单元格背景色和单元格文字颜色设置

标签:

原文地址:http://blog.csdn.net/zhishiheng/article/details/45060399

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!