//CXGrid在OnCustomDrawCell里处理显示 procedure TMainForm.cxGrid1DBTableView1WageCustomDrawCell( Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean); var S,ATextToDraw: String; i, x, y, iTextWidth: Integer; Rect: TRect; begin ATextToDraw := AViewInfo.GridRecord.DisplayTexts[AViewInfo.Item.Index]; Rect:=AViewInfo.Bounds; with ACanvas.Canvas do begin iTextWidth := TextWidth('8') + 4; y := Rect.Top + (Rect.Bottom - Rect.Top - TextHeight('8')) div 2; S := StringReplace(FormatFloat('0.00', AViewInfo.Value), '.', ', []); if AViewInfo.Value < 0 then Font.Color := clRed;
FillRect(Rect);
i := (Rect.Right - Rect.Left) div iTextWidth; repeat x := Rect.Right - iTextWidth * i; if i <= Length(S) then TextOut(x+3, y, S[Length(S)-i+1]);
if i = 2 then Pen.Color := clRed else if (i = 0) or ( (i>2) and (((i-2) mod 3) = 0) ) then Pen.Color := clGreen else Pen.Color := clSilver; MoveTo(x, Rect.Top); LineTo(x, Rect.Bottom); Dec(i); until (i<0); ACanvas.FrameRect(Rect); ADone:=True; end; end;