I have a TStringGrid with several rows in which I implemented some kind of ‘read-only’ row. More exactly, I don’t allow the user to click the penultimate row. If the user clicks the last row nothing happens; the focus won’t be moved to the cells of that row.
I have the code (in KeyDown) and everything works smooth. However, if the user clicks the top row and then uses the mouse wheel to scroll down, eventually the focus will move to the penultimate row. Any idea how to prevent this?
Well, you could override
DoMouseWheelDownto achieve this.But how do you know that there isn’t some other way to move the focus to the last row?
In fact a much better solution is to override
SelectCell:When you do it this way you don’t need any
KeyDowncode, and you don’t need to overrideDoMouseWheelDown. All possible mechanisms to change the selected cell to the final row will be blocked by this.As @TLama correctly points out, you don’t need to sub-class
TStringGridto achieve this. You can use theOnSelectCellevent: