• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 649
  • Last Modified:

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.
0
OutOfLuck
Asked:
OutOfLuck
1 Solution
 
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now