怎样改变dbgrid的备情颜色(100分)

  • 主题发起人 主题发起人 meiguibao
  • 开始时间 开始时间
M

meiguibao

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TEnterTime.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
var
oldcolor:tcolor;
oldpm:tpenmode;
begin
if DateToStr(now) = DateToStr(Dmd.WorkTime.FieldByName('workdate').AsDateTime) Then
begin
oldpm:= DbGrid1.Canvas.pen.mode;
oldcolor:= DbGrid1.Canvas.Brush.color;
DbGrid1.Canvas.Brush.color:=clyellow;
DbGrid1.Canvas.pen.mode:=pmmask;
DbGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
DbGrid1.Canvas.Brush.color:=oldcolor;
DbGrid1.Canvas.pen.mode:=oldpm;
end;
end;

以上的代码不知为什么,当在DBGRID中行发生变化后,颜色变化不正常.请指教
 
var
RectTemp : TRect;
begin
inherited;
with DBGridTop do
begin
if State <> [gdSelected, gdFocused] then
begin
if (AdoQinput.RecNo mod 2)=0 then
Canvas.Brush.Color := rgb(239,247,255)
else
Canvas.Brush.Color := rgb(222,237,252);
end;
DefaultDrawColumnCell(Rect, DataCol, Column, State);


if gdSelected in state then
begin
RectTemp := Rect;
Canvas.Brush.Color:=RGB(160,191,223);
Canvas.Font.Color := ClBlack;
DefaultDrawColumnCell(Rect, DataCol, Column, State);
Canvas.Brush.Color := RGB(0,0,0);
Canvas.FrameRect(RectTemp);
end;
end;
我写的,试过多次没有问题,
 
接受答案了.
 
后退
顶部