cxgrid改变选中行颜色

procedure Tfrm_select_case_model_other.dw_1CustomDrawCell(
 Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
 AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  ARec: TRect;
begin
 if AViewInfo.Focused then
 begin
   ARec := AViewInfo.Bounds;
   ACanvas.canvas.brush.color:= clSkyBlue;
   ACanvas.Font.Color := clRed;
   ACanvas.FillRect(ARec);
 end
 else
 begin
   ARec := AViewInfo.Bounds;
   ACanvas.canvas.brush.color:= clWhite;
   ACanvas.Font.Color := clBlack;
   ACanvas.FillRect(ARec);
 end;

end;


var
  ARec: TRect;
  i:integer;
begin
  if AViewInfo.Focused then
  begin
   ARec := AViewInfo.Bounds;
   ACanvas.canvas.brush.color:= clSkyBlue;
   ACanvas.Font.Color := clRed;
   ACanvas.FillRect(ARec);
  end
  else
  begin
   ARec := AViewInfo.Bounds;
   ACanvas.canvas.brush.color:= clWhite;
   ACanvas.Font.Color := clBlack;
   ACanvas.FillRect(ARec);
  end;
  if (AViewInfo.Item.Index = 18) or (AViewInfo.Item.Index = 19) or
    (AViewInfo.Item.Index = 33) or (AViewInfo.Item.Index = 34) or
    (AViewInfo.Item.Index = 48) or (AViewInfo.Item.Index = 49) then
  begin
    ARec := AViewInfo.Bounds;
    ACanvas.canvas.brush.color:= clSkyBlue;
    ACanvas.FillRect(ARec);
  end;
  if (AViewInfo.Item.Index >= 6) and (AViewInfo.Item.Index <= 19) then
  for i := 6 to 19 do
  begin
    if vartostr(AViewInfo.RecordViewInfo.GridRecord.Values[i])= '-' then
    begin
      ARec := AViewInfo.Bounds;
      ACanvas.Font.Color := clRed;
      ACanvas.FillRect(ARec);
    end;
  end;
  if (AViewInfo.Item.Index >= 21) and (AViewInfo.Item.Index <= 34) then
  for i := 21 to 34 do
  begin
    if vartostr(AViewInfo.RecordViewInfo.GridRecord.Values[i]) = '-' then
    begin
      ARec := AViewInfo.Bounds;
      ACanvas.Font.Color := clRed;
      ACanvas.FillRect(ARec);
    end;
  end;



procedure TFm_Rkcx.GD_RkcxBTCustomDrawCell(Sender: TcxCustomGridTableView;
 

ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
 var ADone: Boolean);
var ATextToDraw:String;
  ARec: TRect;
begin
 ATextToDraw := AViewInfo.GridRecord.DisplayTexts[AViewInfo.Item.Index];
 ARec := AViewInfo.Bounds;
 if AViewInfo.GridRecord.Values[6]<1000 then
  ACanvas.Canvas.Font.Color := clRed;
 //整行变色:ACanvas.Canvas.brush.color:=clred;  
 {列的颜色交替
  if AViewInfo.Item.Index mod 2 = 0 then
   ACanvas.Canvas.brush.color := clInfoBk
  else
  ACanvas.Canvas.brush.color := clInactiveCaptionText;
 }
 {行的颜色交替
   if AViewInfo.RecordViewInfo.Index mod 2 = 0 then
  ACanvas.Canvas.brush.color := clInfoBk
 else
  ACanvas.Canvas.brush.color := clInactiveCaptionText; 
 } 
 ACanvas.Canvas.FillRect(ARec);
end;


如果第一个字段的值小于125,用红色背景显示,文字为居中显示

procedure TForm1.cxGrid1DBTableView1CustomDrawCell(
 Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
 AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
   if StrToInt(AViewInfo.GridRecord.DisplayTexts[0])<125 then
    begin
      ACanvas.Brush.Color:=clRed;
      ACanvas.FillRect(AViewInfo.Bounds);
      ACanvas.DrawText(AViewInfo.GridRecord.DisplayTexts[AViewInfo.Item.Index], AViewInfo.Bounds, cxAlignHCenter);
      ADone:=true;
    end;
end;  














本文转自鹅倌51CTO博客,原文链接: http://blog.51cto.com/kaixinbuliao/1219463  ,如需转载请自行联系原作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值