Solved

insert an image into my adotable grid

Posted on 2011-02-14
6
735 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
[X]
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
  • 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
Technology Partners: 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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

628 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