有個問題是在Delphi中使用DBGrid時,如何讓DBGrid中每一行顏色按照用戶自己的意願控制。
1、 數據表的建立
2、程序設置;
procedure 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;
dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state);
end;