rocedure Tinfo.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if query1.FieldByName(’all’).asstring>40’ then
begin
dbgrid1.Canvas.Font.Color:=clred;
dbgrid1.Canvas.Brush.color:=clyellow;
end
else
begin
dbgrid1.Canvas.Font.Color:=clblue;
dbgrid1.Canvas.Brush.color:=clyellow;
end;
procedure Tform1.DrawGrid(Grid:TDBGrid;const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if Grid.DataSource.DataSet.FieldByName('字段').value > 值 then begin
Grid.Canvas.Font.Color:=clblack;
Grid.Canvas.Brush.color:=clwhite;
end
else begin
Grid.Canvas.Font.Color:=clblack;
Grid.Canvas.Brush.color:=clred;
end;
Grid.DefaultDrawColumnCell(rect,datacol,column,state);
end;
可以参考一下
if gdselected in state then
dbgrid2.Canvas.Font.Color:=rgb(255,0,255)
else if dm.monitor.FieldByName('状态').AsString='无效' then
DBGrid2.Canvas.Font.Color:=clred
else if dm.monitor.FieldByName('状态').AsString='其它' then
DBGrid2.Canvas.Font.Color:=rgb(0,128,128);
DBGrid2.DefaultDrawColumnCell(Rect, DataCol, Column, State);
在DBGrid的 onDrawColumnCell事件判断
如
begin
if dm.Q_B_ApplyIndex.FieldByName('assessor').Asstring<>'0' then
begin
dbgrid1.Canvas.Font.Color:=clgreen;
dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state);
end;
end;