2

The OnDrawCell event gives me a "Rect" record so that I know where the real pixel coordinates are:

OnDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);

On the other hand, the OnSelectCell only gives me the row/col coordinates.

OnSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);

How do I translate the row/col to pixel coordinates?

I need those because I need to create a ComboBox at runtime to cover the whole selected cell, but only when the cell is selected. I know how to do everything, but I do not know how to get the coordinates (right now, I am just creating the combo at 0,0 of the parent tStringGrid).

I am using Delphi7, but I think it is a general question and not related to the Delphi version.

PS: I am aware that there are plenty of commercial and freeware components that implement a combobox inside a cell, but I cannot and/or do not want to use them.

Thank you

ZioBit
  • 905
  • 10
  • 29

1 Answers1

5

You can determine cell screen coordinates using CellRect method

P.S. Have you ever tried to integrate controls into StringGrid?
When you meet problems with controls (having grid as Parent) behavior, look at this topic

Community
  • 1
  • 1
MBo
  • 77,366
  • 5
  • 53
  • 86
  • Perfectly what I was looking for. Just for future references: myRect := (sender as TStringGrid).cellRect(aCol, aRow); – ZioBit Jun 12 '16 at 17:36
  • About the integrating... Not really. I am just at the beginning of writing my custom onDrawCell for example... – ZioBit Jun 12 '16 at 17:38
  • 1
    OK, I've added a link about possible future problems. – MBo Jun 12 '16 at 17:47