Form's KeyPreview doesn't work if there is a DataGrid on the form

  • Thread starter Thread starter Andrea
  • Start date Start date
A

Andrea

Hello,

I've to know when a user press these keys: F1, F2, F3 ecc...
I set the KeyPreview=true on the Windows Form but the KeyPress event of
the form is not raised if a DataGrid is on the form.

Is there any workaround?

Thanks!
 
The KeyPress event isn't fired for the function keys at all, regardless
whether a datagrid is on the form. The KeyPress event doesn't handle all
the keys that the KeyDown and KeyUp events handle, e.g., the navigation keys
(Insert, Home, etc.), the arrow keys, the function keys, caps lock, print
screen, etc.

Use the KeyUp and/or KeyDown events instead for the function keys. Please
keep in mind that F1 is commonly the Help key, and there is support for help
via the HelpProvider component.
 
Back
Top