How to load an image into a specific cell in a TDrawGrid

im new to programming and desperately need help on loading an image into a particular cell in a drawgrid for example putting an image into column 1, row 4. However i only want the image to be displayed when this particular cell is clicked on.
OutOfLuckAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SuperdaveCommented:
TDrawGrid doesn't do much automatically; you need to arrange for the image to be displayed on its OnDrawCell event.
0
SuperdaveCommented:
The easier way might be to make a TImage component and move it where you need it on the grid's OnClick event.
0
OutOfLuckAuthor Commented:
I've tried to do that however it doesn't solve my problem because I want each cell to have a different image that is only displayed when it is clicked on. When I use the onclick event all the images in the grid are displayed rather than the one image in the cell.
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Emmanuel PASQUIERFreelance Project ManagerCommented:
You can try that
procedure TForm1.drwgrd1Click(Sender: TObject);
Var
  MouseP:TPoint;
  CellP:TGridCoord;
begin
 With (Sender As TDrawGrid) do
  begin
   MouseP:=ScreenToClient(Mouse.CursorPos);
   CellP:=MouseCoord(MouseP.X,MouseP.Y);
   if (CellP.X=1) And (CellP.Y=4) 
    Then DrawImageInCell(TDrawGrid(Sender),CellP.X,CellP.Y,SomeGraphic);
  end;
end;

procedure DrawImageInCell(DG:TDrawGrid;aCol,aRow:Integer;aGraphic:TGraphic);
Var
 PX,PY,i:Integer;
begin
 PX:=0;
 PY:=0;
 for i:=0 to aCol-1 do PX:=PX+DG.ColWidths[i];
 for i:=0 to aRow-1 do PY:=PY+DG.RowHeights[i];
 DG.Canvas.Draw(PX+2,PY+2,aGraphic);
end;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
calinutzCommented:
Be aware of the State: TGridDrawState when drawing.
Ask delphi if the gdFocused or gdSelected is in State... and treat this case separately.
0
OutOfLuckAuthor Commented:
thankyou
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.