这是对一个字段更改颜色,整行的类似:请参阅如下代码:
procedure TfrmProgramSet.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
// if tblParam.Active then
begin
case DataCol of
7: //最后一列
begin
DBGrid1.Canvas.Brush.Color:=myColor;
DBGrid1.Canvas.FillRect(Rect);
end
else
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
end;
end;
结合上面的代码可以这样:(试试,以前我作过,源代码没了,这是凭记忆的,可能
不很正确。
if state=[dsSelected] then
begin
InflateRect(Rect,2,2);
DBGrid1.Canvas.Brush.Color:=myColor;
DBGrid1.Canvas.FillRect(Rect);
DBGrid1.Canvas.Textout(Rect.Left,Rect.Top, Column.AsString);
end
else
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);