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;