Solved

TStringGrid.OnKeyDown event not working

Posted on 2008-10-30
1
976 Views
Last Modified: 2013-11-12
Hi.

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.

Any ideas?



procedure TMyGrid.KeyDown(var Key: Word; Shift: TShiftState);
begin                                                                
 case Key of                        <--- if I pub breakpoint here it works !!!!!!!
   VK_LEFT  : if CursorPos-1 > 0 then
               begin
                  ...
               end;
   VK_DELETE: begin
               inherited KeyDown(Key, Shift);
               DeleteCells(Row);
               Bip30;
              end;
   VK_Up    : begin
                      ...
                    end;

  else inherited KeyDown(Key, Shift);
 end;
end;

PS: VK_Left, VK_Up, etc behave in the same way as VK_delete.
0
Comment
Question by:fedra
1 Comment
 

Accepted Solution

by:
fedra earned 0 total points
ID: 22842200
Fixed. I accidentally set the focus on a different control. So even if the grid had the cursor on it, the focus was on a different control.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 76
Math Question 1 76
Eclipse Neon start with Admin account only 6 91
Currency Conversion? 1 71
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now