请问,怎么在DBGRID中改变CELL内容

本文介绍如何使用 Delphi 在 DBGrid 中自定义单元格内容的显示方式,通过示例代码展示了如何根据字段值改变单元格内的文本。
请问,怎么在DBGRID中改变CELL内容 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiDB/html/delphi_20061216104516278.html
我写了以下代码:但是还是显示数字  
  procedure   TMakeTicket.DBGridEh3DrawColumnCell(Sender:   TObject;  
      const   Rect:   TRect;   DataCol:   Integer;   Column:   TColumnEh;  
      State:   TGridDrawState);  
  begin  
      inherited;  
      with   DBGridEh3.Canvas   do  
      case   ADOQuery2.FieldByName('status').AsInteger   of  
      1:TextRect(Rect,Rect.Left,((Rect.Bottom-Rect.Top)-TextHeight('处理'))   div   2,'处理');  
      2:TextRect(Rect,Rect.Left,((Rect.Bottom-Rect.Top)-TextHeight('未处理'))   div   2,'未处理');  
        end;  
    DBGridEh3.DefaultDrawColumnCell(Rect,   DataCol,   Column,   State);  
  }

去掉inherited试试

procedure   TMakeTicket.DBGridEh3DrawColumnCell(Sender:   TObject;  
      const   Rect:   TRect;   DataCol:   Integer;   Column:   TColumnEh;  
      State:   TGridDrawState);  
  begin  
      inherited;  
      if   Column.FieldName   =   'Status'   then  
      begin  
          with   DBGridEh3.Canvas   do  
          begin  
              FillRect(Rect);  
              case   ADOQuery2.FieldByName('status').AsInteger   of  
              1:TextRect(Rect,Rect.Left,((Rect.Bottom-Rect.Top)-TextHeight('处理'))   div     2,'处理');  
              2:TextRect(Rect,Rect.Left,((Rect.Bottom-Rect.Top)-TextHeight('未处理'))   div   2,'未处理');  
          end;  
      end   else  
      DBGridEh3.DefaultDrawColumnCell(Rect,   DataCol,   Column,   State);

1:TextRect(Rect,Rect.Left,((Rect.Bottom-Rect.Top)-TextHeight('处理'))   div     2,'处理');  
              2:TextRect(Rect,Rect.Left,((Rect.Bottom-Rect.Top)-TextHeight('未处理'))   div   2,'未处理');  
   
  ============可以简洁点  
   
    1:TextOout(Rect.Left,   Rect.Top+2,'处理');  
    2:TextOout(Rect.Left,   Rect.Top+2,'未处理');

1:TextOout(Rect.Left+2,   Rect.Top+2,'处理');  
    2:TextOout(Rect.Left+2,   Rect.Top+2,'未处理');

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值