在dbgrid中显示图象的例子,
你可以改一下,原理是一样的
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
Bmp: TBitmap;
OutRect: TRect;
BmpWidth: Integer;
begin
// default output rectangle
OutRect := Rect;
if Column.Field = Table1Common_Name then
begin
// draw the image
Bmp := TBitmap.Create;
try
Bmp.Assign (Table1Graphic);
BmpWidth := (Rect.Bottom - Rect.Top) * 2;
OutRect.Right := Rect.Left + BmpWidth;
DBGrid1.Canvas.StretchDraw (OutRect, Bmp);
finally
Bmp.Free;
end;
// reset output rectangle, leaving space for the graphic
OutRect := Rect;
OutRect.Left := OutRect.Left + BmpWidth;
end;
// red font color if length > 100
if (Column.Field = Table1Lengthcm) and
(Table1Lengthcm.AsInteger > 100) then
DBGrid1.Canvas.Font.Color := clRed;
// default drawing
DBGrid1.DefaultDrawDataCell (OutRect, Column.Field, State);
end;