Overriding a menu hotkey

Hello,

I have assigned a hotkey (delete) to clear a range of cells. I want to change the behavior of the delete key when the user is in a cell's edit mode. I would like the delete key to behave normally in this state. Is there a way I can override the delete key as a hotkey?

I am using a generic toolstripmenu item in my toolbar:

ToolStripMenuItem item = new System.Windows.Forms.ToolStripMenuItem();

And I set the hotkey via the item's shortcutkeys property.
item.ShortcutKeys = shortcutKeys;

Currently, when I select a cell and go into edit mode, hitting the delete key will clear the contents of the entire cell. This isn't the behavior that I want. Please let me know if I can change this behavior, thanks!

Andy.

2 Replies

AC Andy Chan May 28, 2010 04:57 PM UTC

sorry, this message should be posted to the essential grid -- windows forms section of the forum... can this be moved?


RC Rajadurai C Syncfusion Team June 2, 2010 04:32 AM UTC

Hi Andy,

Thanks for your interest in Syncfusion Products.

In GridControl under cell edit mode, the default behavior of Delete key is, removing 1 character to the right of the caret position in cell on each key press which is the desired behavior for any editable controls. If the ActivateCurrentCellBehavior property is set to SelectAll, the cell selects entire contents on activation. With this, on pressing Delete key will delete the entire cell contents.

this.gridControl1.ActivateCurrentCellBehavior = GridCellActivateAction.SelectAll;

If you would like to handle this behavior and set the default with the SelectAll property, the following code can be handled in CurrentCellKeyDown event.

this.gridControl1.CurrentCellKeyDown += new KeyEventHandler(gridControl1_CurrentCellKeyDown);

void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
TextBox tb = cc.Renderer.Control as TextBox;
tb.Select(0,0);
}
}


Here is a sample for your reference.
http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=GC_DeleteKey2004313115.zip

If you want any other behavior to implement with certain keys, respective code can be handled in this event accordingly.

Regards,
Arulraj.A

Loader.
Up arrow icon