I have been fooling around with dragging and dropping controls in a grid panel in delphi 2010. Move a panel/button/whateever the contents are from one cell to another cell. Replacing existing or swapping places. I have not figured out how I know which cell was dropped on because they work with column indexes and also row indexes.
so if I have a gridpanel which has 3 columns and 3 rows, and I have a button in cell 1/1... and I drag that button from 1/1 into 3/3 how can I get that cell location from the dragdrop event? I get the x,y coords on the drop but how can I determine the cell from that?
You can use
TGridPanel.CellRect
to get the bounding rectangle for each of the cells. Here's an example of how to useCellRect
:Based on Cosmin's answer (which is a nice starting point but does not work in real-life).
My code is in C++ but since it is a "clone" of Consmin's answer, Delphi users may easily understand it (and see what was changed).
PS: note that I drag TPanels instead of TButtons (a very minor change).