修改DBGrid控件的OnDrawColumeCell事件
例如:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect:TRect;DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Table1.FieldByName('int').AsInteger > 10000 then
DBGrid1.Canvas.Font.Color := clBlue;DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);end;
希望对你有用!
例如:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect:TRect;DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Table1.FieldByName('int').AsInteger > 10000 then
DBGrid1.Canvas.Font.Color := clBlue;DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);end;
希望对你有用!
if Column.fieldname='yourfield' then
DBgrid1.canvas.brush.color:=(yourcolor);//将底色改变
DBgrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);至于选中某一行要使其变色,则可用Rxlib控件中的TRxDbgrid控件
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if (gdSelected in State) then
begin
DBGrid1.Canvas.Brush.Color := clTeal;//选中
DBGrid1.Canvas.Font.Color :=clWhite ;//字体
end
end;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);