2. 在OnDrawColumnCell 中 With DBGrid1.Canvas do begin if ADOQuery1.FieldbyName('ID').AsInteger = 1 then begin //Font..... Brush.Color := clBlue; FillRect(Rect); Brush.Color := clWindow; end; end;
procedure TFm_CheckStat.DBGridEhDataShowDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGridDrawState); begin if Column.FieldName='State' then begin if trim(ADOQCheckStat.FieldByName('State').AsString) = '不正常' then begin DBGridEhDataShow.Canvas.Font.Color := clRed; DBGridEhDataShow.DefaultDrawColumnCell(Rect, DataCol, Column, State); end; end; end;
1、TStringGrid(DBGrid1).FixedCols := 3;锁定左边前两列,有点缺陷就是标题变为白色的了,看不见,所以有要自己修饰一下哦,呵呵比如有两个DBgrid有一个是为了显示标题 2、procedure TdaychuqinFrm.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin Column.Title.Color:=$00FCF2EB; if (gdSelected in State) or (gdFocused in State)then exit; if ((Sender as TDBGrid).DataSource.DataSet.RecNo mod 2)=0 then (Sender as TDBGrid).Canvas.Brush.Color:=$00FCF2EB else (Sender as TDBGrid).Canvas.Brush.Color:=clWhite; (Sender as TDBGrid).Canvas.FillRect(Rect); (Sender as TDBGrid).DefaultDrawColumnCell(Rect,Datacol,column,state); end;//和2楼差不多,呵呵
在OnDrawColumnCell 中 With DBGrid1.Canvas do
begin
if ADOQuery1.FieldbyName('ID').AsInteger = 1 then
begin
//Font.....
Brush.Color := clBlue;
FillRect(Rect);
Brush.Color := clWindow;
end;
end;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
if Column.FieldName='State' then
begin
if trim(ADOQCheckStat.FieldByName('State').AsString) = '不正常' then
begin
DBGridEhDataShow.Canvas.Font.Color := clRed;
DBGridEhDataShow.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
end;
end;
2、procedure TdaychuqinFrm.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
Column.Title.Color:=$00FCF2EB;
if (gdSelected in State) or (gdFocused in State)then
exit;
if ((Sender as TDBGrid).DataSource.DataSet.RecNo mod 2)=0 then
(Sender as TDBGrid).Canvas.Brush.Color:=$00FCF2EB
else
(Sender as TDBGrid).Canvas.Brush.Color:=clWhite;
(Sender as TDBGrid).Canvas.FillRect(Rect);
(Sender as TDBGrid).DefaultDrawColumnCell(Rect,Datacol,column,state);
end;//和2楼差不多,呵呵