views:

298

answers:

2

Delphi 2007.

I have a TGrid with more rows than will fit on the screen, and the height of the grid is such that there is a partially drawn row at the bottom. When I click on this partial row, it jumps up to be fully visible (via a procedure called 'ClampInView' in Grids.pas). But it doesn't stop. Since the mouse is now over a new partially drawn row, that jumps up too.

The net effect is that clicking on the partially drawn row starts selecting cells in a vertical column, spinning all the way to the bottom (or until you release the mouse).

I have replicated this on a fresh winforms project with just a single grid with 100 rows, and no code, so I'm pretty sure it's not something I'm doing in code wrong.

It is bad for me because the form I have in real code has drag and drop type behaviour, so clicking and releasing ~0.1 seconds later on the partial row will pick up the item in the cell and drop it about 50 rows lower. This is definitely not what you expect to happen when you click on a cell.

Any suggestions how to fix/work around this?

A: 

You can try override MouseDown in your grid and do not call inherited MouseDown, if user clicks in "bad" places.

Jk
+1  A: 

This is what I have always done because I think it is tacky to have partially visible rows. I adjust the size of the grid so its client area is an even multiple of row height. You can do that at design time, or it is easy to do via code as well. The kicker would be if you have re-sizable rows. If that is the case then just put the code to resize the grid in the event handler for the row resize event (I believe it has one).

Not only does this prevent the behavior you are trying to fix, but it also (in my opinion) makes your UI look a lot cleaner!

Jim McKeeth