先将DBGrid的option里rowselect设置成true,然后处理DBGrid的DrawColumnCell事件procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin with dbgrid1.Canvas do begin if (gdSelected in State) then begin Brush.Style:=bsClear; Brush.Color:=clblue; FillRect(rect); Font.Color:=clwhite; TextOut(Rect.Left,Rect.Top,Column.Field.DisplayText); end; end; end;
procedure TMainForm.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGridDrawState); begin if not (gdSelected in State) then begin DBGrid1.Canvas.Font.Color := clRed; DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State); end; end;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
with dbgrid1.Canvas do
begin
if (gdSelected in State) then
begin
Brush.Style:=bsClear;
Brush.Color:=clblue;
FillRect(rect);
Font.Color:=clwhite;
TextOut(Rect.Left,Rect.Top,Column.Field.DisplayText);
end;
end;
end;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
if not (gdSelected in State) then
begin
DBGrid1.Canvas.Font.Color := clRed;
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
end;