1.色塊和文字顏色方法
/// <summary>
/// 設置單元格樣式(色塊)
/// </summary>
/// <param name="gc">Devexpress GridView </param>
/// <param name="color">顏色</param>
/// <param name="expression">表達式(條件)</param>
/// <returns></returns>
protected virtual StyleFormatCondition SetStyleFormatCondition(GridColumn gc, Color color, string expression)
{
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;
return condition1;
}
/// <summary>
/// 設置單元格(字體顏色)
/// </summary>
/// <param name="gc">Devexpress GridView</param>
/// <param name="color">顏色</param>
/// <param name="expression">表達式(條件)</param>
/// <returns></returns>
protected virtual StyleFormatCondition SetStyleFormatFontCondition(GridColumn gc, Color color, string expression)
{
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;
return condition1;
}
2.開始調用
gvData.FormatConditions.Add(SetStyleFormatCondition(gvData.Columns["AuditStatus"], Color.FromArgb(56, 173, 40), "AuditStatus=='已審核'"));//審核狀態(色塊)
gvData.FormatConditions.Add(SetStyleFormatFontCondition(gvData.Columns["OrderStatus"], Color.FromArgb(30, 119, 194), "OrderStatus=='未完成'"));//執行狀態(文字顏色)
執行結果: