Mega Code Archive

 
Categories / Delphi / Graphic
 

Icons in DBGrid

Title: Icons in DBGrid Question: How to place icons in DBGrid Answer: You can use the OnDrawColumnCell event to to place icons in DBGrid instead of the values of field. Here's the easy way to do it: procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var Icon: TBitmap; begin Icon:=TBitmap.Create; if (Column.FieldName='SHARES' ) then begin with DBGrid1.Canvas do begin Brush.Color:=clWhite; FillRect(Rect); if (Table1.FieldByName('SHARES').Value4500) then ImageList1.GetBitmap(1,Icon) else ImageList1.GetBitmap(0,Icon); Draw(round((Rect.Left+Rect.Right-Icon.Width)/2),Rect.Top,Icon); end; end;