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



复制代码
 1 private void gvSendConfirm_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
 2         {
 3             string sCurrTime=DbHelperSql.GetSingle("Select GetDate() DateNow").ToString();
 4             DateTime dtCurrTime,dtSendTime;
 5             int iMinutes = 0;
 6             try
 7             {
 8                 dtCurrTime=DateTime.Parse(sCurrTime);
 9             }
10             catch (System.Exception ex)
11             {
12             dtCurrTime=DateTime.Now;
13             }
14 
15             string sSendTime= gvSendConfirm.GetDataRow(e.RowHandle)["UpdateTime"].ToString();
16             try
17             {
18                 dtSendTime = DateTime.Parse(sSendTime);
19             }
20             catch (System.Exception ex)
21             {
22                 dtSendTime = DateTime.Now;
23             }
24 
25             //计算时间差。
26             System.TimeSpan difTime = dtCurrTime.Subtract(dtSendTime);
27             iMinutes = difTime.Minutes;
28 
29             if (iMinutes <= iTimeOutLevel1)
30             {
31                 e.Appearance.BackColor = Color.White;   //设置背景色
32             }
33             else if (iMinutes > iTimeOutLevel1 && iMinutes <= iTimeOutLevel2)
34             {
35                 e.Appearance.BackColor = Color.FromArgb(192, 192, 255);//设置背景色
36             }
37             else if (iMinutes > iTimeOutLevel2 && iMinutes <= iTimeOutLevel3)
38             {
39                 e.Appearance.BackColor = Color.FromArgb(128, 255, 128);//设置背景色
40             }
41             else if (iMinutes > iTimeOutLevel3 && iMinutes <= iTimeOutLevel4)
42             {
43                 e.Appearance.BackColor = Color.FromArgb(255, 192, 128);//设置背景色
44             }
45             else if (iMinutes > iTimeOutLevel4 && iMinutes <= iTimeOutLevel5)
46             {
47                 e.Appearance.BackColor = Color.FromArgb(255, 128, 128);//设置背景色
48             }
49             else if (iMinutes > iTimeOutLevel5 && iMinutes <= iTimeOutLevel6)
50             {
51                 e.Appearance.BackColor = Color.Red;//设置背景色
52             }
53             else if (iMinutes > iTimeOutLevel6)
54             {
55                 e.Appearance.BackColor = Color.Crimson;//设置背景色
56             }
57             e.Appearance.ForeColor = Color.Black; //设置字体颜色
58         }
复制代码

 

posted @   编程世界里晃荡  阅读(1021)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
点击右上角即可分享
微信分享提示