码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2018-06-30 14:47:25      阅读:477      评论:0      收藏:0      [点我收藏+]

标签:dtc   appear   date   exp   end   app   exce   white   cep   


代码:

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背景色。

标签:dtc   appear   date   exp   end   app   exce   white   cep   

原文地址:https://www.cnblogs.com/kliine/p/9246736.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!