Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

insert an image into my adotable grid

Posted on 2011-02-14
6
727 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 117
Using idhttp to login to instagram 2 106
Reconfigure Delphi Install? 2 61
Moving (cutting/pasting) controls in a TTabbedNotebook... 7 44
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

829 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