I am rendering the content of a database table in a TGrid, which works fine. Now I would like to show an image of a trash can on every row as a button to delete the row.
How can this be done?
How to render a TBitmap image in a cell of a TGrid?
996 Views Asked by Peter Holzer At
2
There are 2 best solutions below
0
On
try this code on event onDrawColumnCell
if stgMain.Cells[0, Row] = 'isImage' then begin
Bounds.Location := PointF(Bounds.Location.X, Bounds.Location.Y + ((Bounds.Height - Bounds.Width) / 2));
Bounds.Width := Bounds.Width;
Bounds.Height := Bounds.Width;
Canvas.Fill.Kind := TBrushKind.Bitmap;
Canvas.Fill.Bitmap.WrapMode := TWrapMode.TileStretch;
Canvas.FillRect(Bounds, 0, 0, AllCorners, 1);
Canvas.Fill.Bitmap.Bitmap := FMain.img.Bitmap(Bounds.Size, 2);
end;
There are several ways to paint an image in a Grid. In cases, where the images will be loaded at runtime e.g. from a database, I prefer to use the
OnDrawColumnCellevent:This example expects an
ImageList1with several preloaded images. It draws all images into the column with the nameImageColumn1. To take your images from the database, replace the line with thebmpaccess.Update at 18-Apr-21:
If you simply want to show a trash icon or e.g. a status icon, you can put an image list on the form. Add a
TImageColumnorTGlyphColumn(e.g. as column number 2) and fill the image in this event into the cell:For a trash icon, you can write your delete action into the following event method: