关于在dbgrideh中数理小于0字体的颜色问题 ( 积分: 10 )

  • 主题发起人 主题发起人 admin2008
  • 开始时间 开始时间
A

admin2008

Unregistered / Unconfirmed
GUEST, unregistred user!
就是当在dbgrideh控件当数量小于0时 显示为红色 反之绿色,这是代码 但是没有实现
请高手指点,dbgrideh显示是视图
procedure Tbad_bill_find.DBGridEh1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
if adoquery1.fieldbyname('数量').Value <0 then
//if dbgrideh1.Fields[9].AsInteger<0 then
DBGrideh1.Canvas.Font.Color := clRed
else
DBGrideh1.Canvas.Font.Color := clblue;

end;
 
试一试这个吧,好久没来大富翁,各位还好吗?
procedure Tfrmriji.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
var
oldcolor:Tcolor;
begin
if adoquery1.fieldbyname('数量').Value <0 then
begin
oldcolor:= dbgrideh1.Canvas.font.color;
dbgrideh1.canvas.font.color:=clred;
dbgrideh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
dbgrideh1.canvas.font.color:=oldcolor;
end;
end;
 
少调用了下面的语句,设置好了,要用的啊!
dbgrideh1.DefaultDrawColumnCell(Rect, DataCol, Column, State
 
procedure Tbad_bill_find.DBGridEh1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
if Column.FieldName = '数量' then
if Column.Field.Value < 0 then
DBGrideh1.Font.Color := clRed
else
DBGrideh1.Font.Color := clblue;
end;
 
谢了 来自:ANiDelphi, 时间:2007-10-23 9:31:35, ID:3845063
 
后退
顶部