Solved

insert an image into my adotable grid

Posted on 2011-02-14
6
723 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 36

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 36

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now