怎样让dbgrid里面插入图像,多谢

解决方案 »

  1.   

    怎样在dbgrid里面显示图像
      

  2.   

    procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);
    begin
    dbgrid1.Canvas.Draw(Rect.Left,Rect.Top,application.Icon);
    end;
      

  3.   

    unit DBPicGrd;interfaceuses
      DBGrids, DB, DBTables, Grids, WinTypes, Classes, Graphics;type
      TDBPicGrid = class(TDBGrid)
      protected
        procedure DrawDataCell(const Rect: TRect;
          Field: TField; State: TGridDrawState); override;
      public
        constructor Create(AOwner : TComponent); override;
      published
        property DefaultDrawing default False;
      end;procedure Register;implementationconstructor TDBPicGrid.Create(AOwner : TComponent);
    begin
      inherited Create(AOwner);
      DefaultDrawing := False;
    end;procedure TDBPicGrid.DrawDataCell(const Rect: TRect; Field: TField;
    State: TGridDrawState);
    var
      bmp : TBitmap;
    begin
      with Canvas do
      begin
        FillRect(Rect);
        if Field is TGraphicField then
            try
              bmp := TBitmap.Create;
              bmp.Assign(Field);
              Draw(Rect.Left, Rect.Top, bmp);
            finally
              bmp.Free;
            end
        else
          TextOut(Rect.Left, Rect.Top, Field.Text);
      end;
    end;procedure Register;
    begin
      RegisterComponents('Custom', [TDBPicGrid]);
    end;end.
    
      

  4.   

    procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);
    var
      bmp : TBitmap;
    begin
      with DBGrid1.Canvas do
      begin
        FillRect(Rect);
        if Field is TGraphicField then
            try
              bmp := TBitmap.Create;
              bmp.Assign(Field);
              Draw(Rect.Left, Rect.Top, bmp);
            finally
              bmp.Free;
            end;
      end;
    end;