程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> 關於.NET >> Devexpress GridView 數據根據不同條件格式化顯示色塊和文字顏色,devexpressgridview

Devexpress GridView 數據根據不同條件格式化顯示色塊和文字顏色,devexpressgridview

編輯:關於.NET

Devexpress GridView 數據根據不同條件格式化顯示色塊和文字顏色,devexpressgridview


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=='未完成'"));//執行狀態(文字顏色)

執行結果:

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved