I want to add an image to the selected field in a Delphi 7 dbgrid. The dbgrid displays many fields, and if the user selects a field, I have to add an image to its title.
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
var
index: integer;
begin
//your conditional ....
if (Field.Tag = Field.Dataset.RecNo) and (Field = Table1Field1) then begin
//never mind the Rect we can draw where we like.
index:= 1;
// Rect = cell rectangle
ImageList1.Draw(DBGrdi1.Canvas, 2, Rect.Top, index, dsTransparent);
end
else { use default Draw... }
DBGrid1.DefaultDrawDataCell(Rect, Field, State);
end;
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.