![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Как поместить графическое изображение в TDBGrid ?
Niki © (2003-02-12 14:19:00)Как поместить графическое изображение в TDBGrid? (только без использования компонента TImageList)
Vlad1 (2003-02-13 22:06:00) [1]Например, так:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, Grids, DBGrids, ExtCtrls, DBCtrls, StdCtrls;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Table1: TTable;
DBNavigator1: TDBNavigator;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Table1.Open;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Table1.Close;
end;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var Foto:TBitmap;
OutRect:Trect;
FotoWidth:integer;
begin
OutRect:=Rect;
if Column.FieldName="Photo"
then begin
foto:=TBitmap.Create;
try
foto.Assign(Table1.FieldByName("Photo"));
FotoWidth:=(Rect.Bottom-Rect.Top)*2;
OutRect.Right:=rect.Left+FotoWidth;
DBGrid1.Canvas.StretchDraw(OutRect,Foto);
finally
Foto.Free;
end;//try
OutRect:=Rect;
OutRect.Left:=OutRect.Left+FotoWidth;
DBGrid1.DefaultDrawDataCell(OutRect,column.Field,State);
DBGrid1.Canvas.FillRect(Outrect);
exit;
end;//if;
DBGrid1.DefaultDrawDataCell(OutRect,column.Field,State);
end;
end.
Stas (2003-02-12 14:36:00) [2]Проще использовать другой grid.