Solved

insert an image into my adotable grid

Posted on 2011-02-14
6
725 Views
Last Modified: 2012-06-21
hi, whats the idea and a sample of code so i can insert an image into my adotable, in the same cell as some text.

Meaning

when i select "sale ok" and it inserts my data into the table2, i want to add a small logo/picture next the the text saying "sale ok" and if its not sale i select "bad" and it adds a different image.

is this possible, i really dont want to create another field in the database. If i can help it.
0
Comment
Question by:iplay
  • 3
  • 2
6 Comments
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 34892246
images are stored on the form for displaying

use an imagelist, each image has it's own number
they have to be the same size

with a professional grid, you get a drop down image (like devexpress quantumgrid)
you assign the imagelist to the drop down
then just set the right value for the right image

with dbgrid, it's custom draw
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 34892256
0
 

Author Comment

by:iplay
ID: 34892450
Hi thanks, i found this code but i dont understand how i can show my image and what column to put it in..

can youmodify it so it shows TEST.JPG inside grid2 adotable 2

in column "5" ?
only when column 5 says "sale ok"



procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  Field: TField; State: TGridDrawState);
var
  Bmp: TBitmap;
begin
  if Field is TGraphicField then
  begin
    try
      Bmp:=TBitmap.Create;
      Bmp.Assign(Field);
      DBGrid1.Canvas.StretchDraw(Rect, Bmp);
    finally
      Bmp.Free;
    end
  end
  else
    DBGrid1.DefaultDrawDataCell(Rect,Field,State);
end;
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 32

Accepted Solution

by:
ewangoya earned 500 total points
ID: 34892783
Firts drop and ImageList on your form and add your images to it

First image you add will be for OK so the index is zero
Second image you add will be for Bad, so image index is one

Select the DBGrid1, go to events and double click on OnDrawColumnCell
 Delphi will create the procedure

procedure TForm3.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin

end;

Add this code to it
procedure TForm3.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
  Bitmap: TBitmap;
  R: TRect;
  Index : integer;
begin
  Index := -1;
  if LowerCase(Column.Field.AsString) = 'sale ok' then
    Index := 0
  else if LowerCase(Column.Field.AsString) = 'bad' then
    Index := 1;

  if Index >= 0 then
  begin
    //draw image
    Bitmap := TBitmap.Create;
    try
      ImageList1.GetBitmap(Index, Bitmap);
      R := Rect;
      R.Right := Rect.Left + ImageList1.Width;
      DBGrid1.Canvas.StretchDraw(R, Bitmap);
    finally
      FreeAndNil(Bitmap);
    end;

    //Add the text
    R := Rect;
    R.Left := Rect.Left + ImageList1.Width;

    DBGrid1.DefaultDrawColumnCell(R, DataCol, Column, State);
  end;
end;

Open in new window

0
 

Author Comment

by:iplay
ID: 34892946
perfect as always and a perfect explanation. Thanks!
0
 

Author Closing Comment

by:iplay
ID: 34892950
A+++++
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question