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); } } }
时间: 2024-10-30 08:03:56