Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to add an image on the selected field in a dbgrid in Delphi 7

sysmatics

IS-IT--Management
Apr 30, 2009
3
IN
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.

Thanks,
Sridhar
 

Attachments

  • Screenshot (125).png
    Screenshot (125).png
    62.6 KB · Views: 2
try this:

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;
 

Part and Inventory Search

Sponsor

Back
Top