Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

insert an image into my adotable grid

Posted on 2011-02-14
6
Medium Priority
?
745 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 38

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 38

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

885 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