| Subject: | DBGrid.OnKeyPress |
| Posted by: | Frank Marousek (fra…@n-c-systems.com) |
| Date: | Tue, 27 Oct 2009 |
Using D2010...
I have a form with a DBGrid, an edit box, and a "Search" button. This is
a typical form to allow the user to enter a complete or partial part
number into the edit box, press "Search", and have the DBGrid populated
with a set of matching records, from which the user may select which
record he wants for editing.
I provide four ways to trigger an edit: 1) select a record and click an
"Edit" button, 2) double-click on desired record, 3) right click on a
record and select Edit from a pop-up menu, or 4) select a record and
press the Enter key. The first three are working fine, the fourth is not.
In running this through the debugger, I was able to determine that if
the Default property of the Search button is set to True, when the user
attempts to select a record for editing by pressing Enter the Search
button OnClick event is triggered, i.e. the keystroke is being handled
by the form instead of the DBGrid. If I set the Search Button.Default
property to False, then the DBGrid.OnKeyPress event is triggered and
everything works as I want. Of course I would prefer for the Search
button.Default property to be set to True.
The only property I was able to find that might alter this behavior is
the Form.KeyPreview property, which, if I understand it correctly,
should be set to True if the form is to have priority in handling
keystrokes, and set to False if not. My form's KeyPreview property is
set to False.
Can anyone explain why this is happening, and what I should change to
make it work as I want?