打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
CxGrid 改变某行或单元格的颜色


一个表(T)的结构结构如下.



ID Test



1 2001

2 1444

3 1788

5 2645

6 4568



cxGrid成功连接到该表, 如果要实现单元格特效, 就要在cxGridDBTableView的 OnCustomDrawCell

写代码. 该事件声明原形为



type

   TcxGridTableDataCellCustomDrawEvent = procedure(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean) of object;



参数 Sender: 你要实现特效的TableView; ACanvas: 画布, 这个参数比较重要, 就是用这个参数画出



特效; AViewInfo: 自定义条件的来源; 从这个参数中获取单元格值; ADone: 设为真就不会Paint.



下面是以 Test字段的值来控件单元格颜色



var

   CheckValue: integer;

   cxColumn: TcxGridColumn;

begin



   cxColumn := (Sender as TcxGridDBTableView).GetColumnByFieldName('Test');

   if cxColumn = nil then

     Exit;



//这个条件用来限制是否只Paint指定的单元格, 去掉则Paint整行.

   if SameText(AViewInfo.Item.Name, cxColumn.Name) then begin

     CheckValue := AViewInfo.GridRecord.Values[gdtvTestTest.Index]; //获取单元格

     //以下是满足条件的字体变色

     if CheckValue >= 4000 then //大于4000为红色

       ACanvas.Font.Color := clRed

     else if CheckValue >= 3000 then //大于3000绿色

       ACanvas.Font.Color := clGreen

     else if CheckValue >= 2000 then //大于2000蓝色

       ACanvas.Font.Color := clBlue;



   //以下是满足条件的数据背景变色

   {if CheckValue >= 4000 then begin //大于4000为红色

     AViewInfo.Focused;

     ACanvas.Brush.Color := clRed

   end

   else if CheckValue >= 3000 then //大于3000绿色

     ACanvas.Brush.Color := clGreen

   else if CheckValue >= 2000 then //大于2000蓝色

     ACanvas.Brush.Color := clBlue; }



   end;



end;


  
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
delphi 改变cxgrid的行颜色
Cxgrid单元格颜色显示
cxgrid使用方法
delphi中cxGrid使用汇总(二) (转)
每日Excel分享(VBA)| 如何在Excel中实现多选下拉菜单?
delphi中如何在cxGrid中动态增加合计行(footer)?_Delphi之家_NO...
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服