在它的 DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState);中加入 if ds.DataSet =aFee then begin if trim(AFee.FieldByName('IsFinish').AsString) ='1' then DBGRID1.Canvas.Font.Color := clblack else if trim(AFee.FieldByName('IsFinish').AsString) ='0' then DBGRID1.Canvas.Font.Color := clRed; DBGRID1.DefaultDrawDataCell(Rect, Field, State); end;
定义一个在Private 中的整型变量i在OnDrawColumnCell写下: if i div2=0 then DBGrid1.Canvas.Brush.Color:=clRead else DBGrid1.Canvas.Brush.Color:=clWhite; DBGrid1.Canvas.FillRect(Rect);i:=i+i;
写错了
div和2间有个空格
to lihao_ningxia(耗子) 没解决实质的问题,网格的颜色不是根据数据来更换的
procedure TForm_Main.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin with DBGrid1.Canvas do begin if 你的条件 then DBGrid1.Canvas.Brush.Color:= clBackground end; DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); end;
使用这个吧,我刚实验通过了 procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin with DBGrid1.Canvas do begin if DBGrid1.DataSource.DataSet.RecNo mod 2 = 0 then DBGrid1.Canvas.Brush.Color:= clBackground else DBGrid1.Canvas.Brush.Color := clOlive; end; DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); end;
DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);中加入
if ds.DataSet =aFee then
begin
if trim(AFee.FieldByName('IsFinish').AsString) ='1' then
DBGRID1.Canvas.Font.Color := clblack
else if trim(AFee.FieldByName('IsFinish').AsString) ='0' then
DBGRID1.Canvas.Font.Color := clRed; DBGRID1.DefaultDrawDataCell(Rect, Field, State);
end;
if i div2=0 then
DBGrid1.Canvas.Brush.Color:=clRead
else
DBGrid1.Canvas.Brush.Color:=clWhite;
DBGrid1.Canvas.FillRect(Rect);i:=i+i;
div和2间有个空格
没解决实质的问题,网格的颜色不是根据数据来更换的
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
with DBGrid1.Canvas do
begin
if 你的条件 then
DBGrid1.Canvas.Brush.Color:= clBackground
end;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
with DBGrid1.Canvas do
begin
if DBGrid1.DataSource.DataSet.RecNo mod 2 = 0 then
DBGrid1.Canvas.Brush.Color:= clBackground
else DBGrid1.Canvas.Brush.Color := clOlive;
end;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;