Windows Forms Datagrid and Form.KeyPreview

  • Thread starter Thread starter Carl Tribble
  • Start date Start date
C

Carl Tribble

I am using KeyPreview on the form to trap Function-keys. My form includes a
datagrid. I am using the Form.KeyDown event to trap the keys and all works
fine unless the datagrid is showing one or more rows and the focus is in a
column on one of the datagrid's rows. Then, pressing a function key does
not seem to execute the Form.KeyDown event.

How can I trap and detect which function key a user pressed at the form
level from inside of a filled datagrid?

Thanks,
-Carl
 
Hi,

http://64.78.52.104/FAQ/WinForms/FAQ_c44c.asp#q836q

Ken
------------------
I am using KeyPreview on the form to trap Function-keys. My form includes a
datagrid. I am using the Form.KeyDown event to trap the keys and all works
fine unless the datagrid is showing one or more rows and the focus is in a
column on one of the datagrid's rows. Then, pressing a function key does
not seem to execute the Form.KeyDown event.

How can I trap and detect which function key a user pressed at the form
level from inside of a filled datagrid?

Thanks,
-Carl
 
Thanks, Ken. I downloaded the sample code and experimented with it for
awhile. It works of course but it also produces some side effects that, in
my case at least, are undesirable. For one you can no longer select an
entire row by clicking on the row header. You have to click it twice.
Also, and more importantly, it seems that you can not delete the contents of
a cell.

Perhaps these matters can be fixed by altering the code slightly. I tried a
few things with no success. Is there another solution to this problem? Or
do you know a way to deal with those side-effects (at least the not being
able to delete problem)?

Thanks,
-Carl
 
Back
Top