怎样在StringGrid中以不同的颜色显示记录,最好给个例子!(100分)

  • 主题发起人 主题发起人 xjzcg
  • 开始时间 开始时间
X

xjzcg

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样在StringGrid中以不同的颜色显示记录,最好给个例子![:)]
 
利用DBGrid1DrawDataCell,例子如下:
procedure TReceiptGoodsForm.DBGrid1DrawDataCell(Sender: TObject;
const Rect: TRect; Field: TField; State: TGridDrawState);
var
TempI: Integer;
begin
TempI:=DM.YourQuery.Fields[0].AsInteger;
if TempI>0 then
DBGrid1.Canvas.Brush.Color:=clRed
else
if TempI<0 then
DBGrid1.Canvas.Brush.Color:=clGreen;
DBGrid1.DefaultDrawDataCell(Rect, Field, State);
end;
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=733401
 
使用StringGrid的OnDrawCell事件,正如上面所说
 
procedure TjsfxFrm.sshqlistDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
strFsize, valFsize: integer;
clup, cldown, clp: tcolor;
font: tfont;
width, height, cpos: integer;
tmpGrid: Tstringgrid;
tmpstr, tmpstr1: string;
tmpreal, tmppre, tmpclose: real;
realfmt: string;
intfmt, scrb, zqrb: string;
begin
tmpgrid := sender as tstringgrid;
if(ARow mod 2)=0 then
tmpgrid.Canvas.Brush.Color := clblack
else
tmpgrid.Canvas.Brush.Color := clRed
tmpgrid.Canvas.FillRect(Rect);
 
多人接受答案了。
 
后退
顶部