DEV GridControl 根据单元格值改变背景色
GridControl 根据单元格值改变背景色(需要用到CustomDrawCell事件)
方法1:
private void gdvClient_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
if (e.Column.FieldName == "VerifyCN") //指定列
{
if ((string)e.CellValue == "未确认") //条件 e.CellValue 为object类型
e.Appearance.BackColor = Color.Red;
}
}
方法2:
private void gdvStatistics_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { DevExpress.Utils.AppearanceDefault appRed = new DevExpress.Utils.AppearanceDefault (Color.Black, Color.Red, Color.Empty, Color.Red, System.Drawing.Drawing2D.LinearGradientMode.Horizontal); DevExpress.Utils.AppearanceDefault appYellow = new DevExpress.Utils.AppearanceDefault (Color.Black, Color.Yellow, Color.Empty, Color.Yellow, System.Drawing.Drawing2D.LinearGradientMode.Horizontal); DevExpress.Utils.AppearanceDefault appGreen = new DevExpress.Utils.AppearanceDefault (Color.Black, Color.Green, Color.Empty, Color.Green, System.Drawing.Drawing2D.LinearGradientMode.Horizontal); if (e.Column.FieldName == "Difference")//指定列 { string strTemp = gdvStatistics.GetRowCellDisplayText(e.RowHandle, "Difference").ToString().Trim(); if (Convert.ToInt32(strTemp) > 0) DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, appRed); else if (Convert.ToInt32(strTemp) == 0) DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, appGreen); else DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, appYellow); } }