#region 设置单元格样式(设置背景色) ////// 设置单元格样式(设置背景色) /// /// /// "States";"OrderStatus" /// Color.Green;Color.FromArgb(30, 119, 194) /// 表达式(条件),如[LowPrice] > [PrevPrice];"AuditStatus=='已审核'";[Name] != ? public static void SetStyleFormatCondition(this GridView gridView, string fieldName, Color color, string expression) { GridColumn gc = gridView.Columns[fieldName]; StyleFormatCondition condition1 = new DevExpress.XtraGrid.StyleFormatCondition(); condition1.Column = gc; condition1.Appearance.BackColor = color; condition1.Appearance.Options.UseBackColor = true; condition1.Condition = FormatConditionEnum.Expression; condition1.Expression = expression; gridView.FormatConditions.Add(condition1); } /// /// 设置单元格样式(设置背景色) /// /// /// "States";"OrderStatus" /// Color.Green;Color.FromArgb(30, 119, 194) /// FormatConditionEnum.Equal;None,Equal,NotEqual,Between,NotBetween,Less,Greater,GreaterOrEqual,LessOrEqual,Expression, /// 0;"已提交" /// 用于两个值取区间 public static void SetStyleFormatCondition(this GridView gridView, string fieldName, Color color, FormatConditionEnum condition, object conditionValue1, object conditionValue2) { GridColumn gc = gridView.Columns[fieldName]; StyleFormatCondition condition1; if (conditionValue2 == null) { condition1 = new DevExpress.XtraGrid.StyleFormatCondition(condition, gc, null, conditionValue1); } else { condition1 = new DevExpress.XtraGrid.StyleFormatCondition(condition, gc, null, conditionValue1, conditionValue2); } condition1.Appearance.BackColor = color; condition1.Appearance.Options.UseBackColor = true; gridView.FormatConditions.Add(condition1); } #endregion #region 设置单元格(字体颜色) /// /// 设置单元格(字体颜色) /// /// /// "States";"OrderStatus" /// Color.Green;Color.FromArgb(30, 119, 194) /// 表达式(条件),如[LowPrice] > [PrevPrice];"AuditStatus=='已审核'";[Name] != ? public static void SetStyleFormatFontCondition(this GridView gridView, string fieldName, Color color, string expression) { GridColumn gc = gridView.Columns[fieldName]; StyleFormatCondition condition1 = new DevExpress.XtraGrid.StyleFormatCondition(); condition1.Column = gc; condition1.Appearance.ForeColor = color; condition1.Appearance.Options.UseForeColor = true; condition1.Appearance.Options.UseTextOptions = true; condition1.Condition = FormatConditionEnum.Expression; condition1.Expression = expression; gridView.FormatConditions.Add(condition1); } /// /// 设置单元格(字体颜色) /// /// /// "States";"OrderStatus" /// Color.Green;Color.FromArgb(30, 119, 194) /// FormatConditionEnum.Equal;FormatConditionEnum.GreaterOrEqual /// 0;"已提交" /// 用于与conditionValue1求区间范围 public static void SetStyleFormatFontCondition(this GridView gridView, string fieldName, Color color, FormatConditionEnum condition, object conditionValue1,object conditionValue2 = null) { GridColumn gc = gridView.Columns[fieldName]; StyleFormatCondition condition1; if (conditionValue2 == null) { condition1 = new DevExpress.XtraGrid.StyleFormatCondition(condition, gc, null, conditionValue1); } else { condition1 = new DevExpress.XtraGrid.StyleFormatCondition(condition, gc, null, conditionValue1, conditionValue2); } condition1.Appearance.ForeColor = color; condition1.Appearance.Options.UseForeColor = true; condition1.Appearance.Options.UseTextOptions = true; gridView.FormatConditions.Add(condition1); } #endregion
设置列背景色 https://www.cnblogs.com/MuNet/p/5736172.html
Devexpress GridView 数据根据不同条件格式化显示色块和文字颜色 http://www.zhimengzhe.com/asp_netjiaocheng/161557.html
Devexpress Winform Gridcontrol 中根据条件单元格的值改变单元格的颜色等属性。 http://www.lxway.com/668495256.htm
condition1.Expression = "[Name] != ?"; //Name字段不为空
cn.Appearance.BackColor = Color.Green;