1. 程式人生 > >C# - Winform - DevExpress - GridControl 任意條件控制Row背景色。

C# - Winform - DevExpress - GridControl 任意條件控制Row背景色。

dev trac scu timespan per date 字體 orm level


代碼:

private void gvSendConfirm_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
string sCurrTime=DbHelperSql.GetSingle("Select GetDate() DateNow").ToString();
DateTime dtCurrTime,dtSendTime;
int iMinutes = 0;
try
{
dtCurrTime=DateTime.Parse(sCurrTime);
}
catch (System.Exception ex)
{
dtCurrTime=DateTime.Now;
}

string sSendTime= gvSendConfirm.GetDataRow(e.RowHandle)["UpdateTime"].ToString();
try
{
dtSendTime = DateTime.Parse(sSendTime);
}
catch (System.Exception ex)
{
dtSendTime = DateTime.Now;
}

//計算時間差。
System.TimeSpan difTime = dtCurrTime.Subtract(dtSendTime);
iMinutes = difTime.Minutes;

if (iMinutes <= iTimeOutLevel1)
{
e.Appearance.BackColor = Color.White; //設置背景色
}
else if (iMinutes > iTimeOutLevel1 && iMinutes <= iTimeOutLevel2)
{
e.Appearance.BackColor = Color.FromArgb(192, 192, 255);//設置背景色
}
else if (iMinutes > iTimeOutLevel2 && iMinutes <= iTimeOutLevel3)
{
e.Appearance.BackColor = Color.FromArgb(128, 255, 128);//設置背景色
}
else if (iMinutes > iTimeOutLevel3 && iMinutes <= iTimeOutLevel4)
{
e.Appearance.BackColor = Color.FromArgb(255, 192, 128);//設置背景色
}
else if (iMinutes > iTimeOutLevel4 && iMinutes <= iTimeOutLevel5)
{
e.Appearance.BackColor = Color.FromArgb(255, 128, 128);//設置背景色
}
else if (iMinutes > iTimeOutLevel5 && iMinutes <= iTimeOutLevel6)
{
e.Appearance.BackColor = Color.Red;//設置背景色
}
else if (iMinutes > iTimeOutLevel6)
{
e.Appearance.BackColor = Color.Crimson;//設置背景色
}
e.Appearance.ForeColor = Color.Black; //設置字體顏色
}

C# - Winform - DevExpress - GridControl 任意條件控制Row背景色。