TStringGrid.OnKeyDown event not working
Posted on 2008-10-30
I have a very strange behavior with OnKeyDown event for a TStringGrid control.
I have a heavily modified control derived from TStringGrid. In this control I intercept the "key down" in order to delete the selected cell(s) when the user presses the Delete key on his keyboard.
It worked until recently when I discovered that pressing the Delete key does nothing.
STRANGE is that if I put a break point at the beginning of the procedure, the programs step through code and the program works (the code is executed). After this "glitch" is overpass first time, then the program will always work ok.
There is a trick that will do the work: I need to click (focus) another control on the same form where my grid is placed then to return (click) to the grid. After this, the Delete key is working.
procedure TMyGrid.KeyDown(var Key: Word; Shift: TShiftState);
case Key of <--- if I pub breakpoint here it works !!!!!!!
VK_LEFT : if CursorPos-1 > 0 then
inherited KeyDown(Key, Shift);
VK_Up : begin
else inherited KeyDown(Key, Shift);
PS: VK_Left, VK_Up, etc behave in the same way as VK_delete.