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

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!
 
D

durstin

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top