tags:

views:

208

answers:

2

In a simple dialog app, using designer, I've set up the usual shortcut keys for cut, copy, paste and delete in the edit menu.

My problem is that I only want to handle delete events when a certain tree control is in focus. Otherwise, in my datagrid control for example, I want delete to work as usual.

What's the best way to do this? Currently I'm getting a delete event in the main form class, but the delete key isn't working in the edit controls in the datagrid control.

Edit - specified that the delete key isn't working in edit sub-controls

+1  A: 

If you're only going to have one form and only one datagrid, the simplest method would be to fire off your datagrid delete events from the click event invoked by your menu item. Whichever row is current (bindingsource) or selected (datagrid), you can delete programmatically.

Patrick Manderson
Ah, I probably wasn't quite clear. It's the edit windows in the datagrid control where the delete key isn't working. I'll edit my question.
James Hopkin
+1  A: 

It seems that if you want to use the shortcut keys for menuitems, that keycombination is taken throughtout your form, no matter if you set up your eventhandler to not do anything unless a certain tree control is in focus (there is no way to set the keyevent as .Handled=false).

So the best way would be to NOT set the shortcutkey in the menustrip, but instead hook the KeyDown event on the form (keypreview) or on the specific tree control, and handle whatever the delete shortcut key should do there.

If you need the shortcut text to show even though you have no shortcut key defined in the menustrip, use the .ShortcutKeyDisplayString property on the menuitem to set a text.

Wolf5