procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if Table1.FieldByName('Population').AsInteger > 20000000 then TDBGrid(Sender).Canvas.Font.Color := clBlue; TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State); end;
procedure TFrmVendor.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin try try if not (gdFocused in State) then begin with DBGrid1.Canvas do begin if T_VENDPROVVStatus.AsBoolean then Font.Color := clBtnText else font.Color := clred end; end; finally DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); end; except end; end;
procedure TForm5.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var i:integer; begin if (DBGrid1.DataSource.DataSet.RecNo mod 2 = 0 ) then begin dbgrid1.Canvas.Font.Color:=CLRed; end else begin dbgrid1.Canvas.Font.Color:=CLBlue; end; dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state); end;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if Table1.FieldByName('Population').AsInteger > 20000000 then
TDBGrid(Sender).Canvas.Font.Color := clBlue;
TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column,
State);
end;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
try try
if not (gdFocused in State) then
begin
with DBGrid1.Canvas do
begin
if T_VENDPROVVStatus.AsBoolean then
Font.Color := clBtnText
else
font.Color := clred
end;
end;
finally
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end; except
end;
end;
这就是只让行变色
TDBGrid(Sender).Canvas.brush.color:=blue;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
i:integer;
begin
if (DBGrid1.DataSource.DataSet.RecNo mod 2 = 0 ) then
begin
dbgrid1.Canvas.Font.Color:=CLRed; end
else
begin
dbgrid1.Canvas.Font.Color:=CLBlue; end;
dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state);
end;