Fórum Colocar imagem em no dbgrid #204811
07/01/2004
0
Galera, gostaria de saber como eu faço para colocar uma imagem do
lado esquerdo de uma célula no dbgrid junto com uma string.
Na célula apareceria a imagem e depois a sua descrição, como por
exemplo, para cada nome de um país, existiria uma bandeira
correpondente antes de iniciar o nome do respectivo país.
lado esquerdo de uma célula no dbgrid junto com uma string.
Na célula apareceria a imagem e depois a sua descrição, como por
exemplo, para cada nome de um país, existiria uma bandeira
correpondente antes de iniciar o nome do respectivo país.
Edukobra
Curtir tópico
+ 0
Responder
Posts
07/01/2004
Nigro
unit DBPicGrd;
interface
uses
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;
implementation
constructor 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.
interface
uses
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;
implementation
constructor 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.
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)