PositionAtPoint Giving wrong cell

Jun 23, 2009 at 2:26 PM

Hey, I have found what I think to be a bug, but do not know if I am just using it wrong. Help!

MouseUp Event ...
Cell cell = (Cell)grid1.GetCell(grid1.PositionAtPoint(e.Location));
...

If I click in the middle of the cell, I get the cell back, if I click on the line between two cells, I end up getting cell [0,0] opposed to a range, or one of the two cells on either side.

Help!

Derek

Jun 23, 2009 at 3:08 PM
Edited Jun 23, 2009 at 3:09 PM

I figured it out, in case anyone else has this issue.

1) The grid is not a cell, so the x/y co-ords on a mouse event are not relative to the grid client window. Example: My mouse x,y when clicking on the middle of my grid is  X=0 Y=5 where I would have expected a few 100 for the x.

The Fix:

On any code that you need to use the point X,Y do the following to the correct "base" starting point.

someEvent (Object sender, EventArgs e)
Forms.Control ctrl = sender as ...Control;
Point tmpPoint = ctrl.PointToScreen (e.Location);
Point tmpPoint2 = grid1.PointToClient(tmpPoint);

Voila, use tmpPoint2 for all of your PositionAtPoint calls.

Derek