起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 236|回复: 3

【搞定】在datagrid 中将数据按不同的颜色显示出来**

[复制链接]
发表于 2007-11-23 09:25:00 | 显示全部楼层 |阅读模式
根据字段值的不同显示为不同的颜色, 在delphi 里面的dbgrid有rawColumnCell 事件, 但x3 的 datagrid 没有该事件,

If Query.fieldbyname('字段名').values 满足条件 then
  Begin
    Dbgrid.Canvas.Brush.Color := 颜色(如:clInfoBk) ;
    Dbgrid.DefaultDrawColumnCell( Rect, DataCol, Column,      

[gdFixed,gdFocused,gdSelected] );
  End ;

请问,在x3中该如何达到这样的效果呢?
回复

使用道具 举报

发表于 2007-11-23 10:22:56 | 显示全部楼层
DataGrid有的,是 OnCustomDrawCell
回复 支持 反对

使用道具 举报

发表于 2007-11-29 14:29:11 | 显示全部楼层

[新版]

在DataGrid 的 OnCustomDrawCell 事件:
----------------------------------------------------------------------
procedure TTMPKYDISPATCHLOGLIST.DataGridCustomDrawCell(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TTreeListNode; AColumn: TTreeListColumn; ASelected, AFocused, ANewItemRow: Boolean; var AText: string; var AColor: Integer; AFont: TFont; var AAlignment: TAlignment; var ADone: Boolean);
begin
   //处理高亮和间隔显示
   if not(ASelected or AFocused) and ((ANode.Index mod 2)=1) then
   AColor := $EAEAEA;
   //判断记录类型为提醒注意、闭环跟踪且状态为新建、修改的高亮显示;其他的普通显示
   if (InfoBroker.Info.DataSetByID('tmpKYDispatchlog').FieldByName('FRecType').AsString = '2') and
      (InfoBroker.Info.DataSetByID('tmpKYDispatchlog').FieldByName('FStatus').asstring<>'3')  then
   begin
      AColor := Graphics.clBlue;
      AFont.Color := Graphics.clRed;
   end
   else
   if (InfoBroker.Info.DataSetByID('tmpKYDispatchlog').FieldByName('FRecType').AsString = '3') and
      (InfoBroker.Info.DataSetByID('tmpKYDispatchlog').FieldByName('FStatus').asstring<>'3') then
   begin
      AColor := Graphics.clRed;  //数据记录背景颜色
      AFont.Color := Graphics.clBlue;  //数据记录字体颜色
   end;
  // AColumn.Color := Graphics.clRed;
end;
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-12-6 10:45:40 | 显示全部楼层
请结帖, 谢谢!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-7-1 22:18 , Processed in 0.037518 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表