想要dbgrid能够随着数据项的变化来改变颜色,比如数据项是空的,显示蓝色,不空显示红色的,

解决方案 »

  1.   

    这样写:
    procedure TForm1.BGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
     with DBgrid1 do
       begin
         if datasource.dataset.fieldbyname('字段').asboolean=true then//条件可以自己设定
           begin
            canvas.font.color:=clblue;
            DefaultDrawColumnCell(rect,datacol,column,state);
           end
       end;
    end;