I have a simple .net application containing tabs and datargridviews on each tab. I added the main menu to the form and assigned shortcuts for menu items using the standard property:
editMenuItem = new ToolStripMenuItem("Copy", null, new System.EventHandler(onCopyCut_Click));
editMenuItem.ShortcutKeys = Keys.Control | Keys.C;
The menu item shown above simply copies the contents of the cell to the clipboard. This works great, but in DGV editing mode, Ctrl + C and other standard hotkeys no longer work!
I set the property Form.KeyPreviewto true, also tried to disable the Processed property of my Form object, but nothing happens:
void FileOrginizerForm_KeyDown(object sender, KeyEventArgs e)
{
...
if (gridView.CurrentCell.IsInEditMode)
e.Handled = false;
}
What am I missing? I am sure that this should be something simple.
msdn :
, , , , ShortcutKeys , , . (ctrl + v) ShortcutKey, . Microsoft, . ShortCutKey, ( , ), reset .
:
, Form KeyDown:
void FileOrginizerForm_KeyDown(object sender, KeyEventArgs e)
{
if (!gridView.CurrentCell.IsInEditMode)
{
if (e.KeyData == (Keys.Control | Keys.Z))
{
this.editToolStripMenuItem.DropDownItems["Undo"].PerformClick();
}
else if (e.KeyData == (Keys.Control | Keys.Y))
{
this.editToolStripMenuItem.DropDownItems["Redo"].PerformClick();
}
else if (e.KeyData == (Keys.Control | Keys.X))
{
this.editToolStripMenuItem.DropDownItems["Cut"].PerformClick();
}
else if (e.KeyData == (Keys.Control | Keys.C))
{
this.editToolStripMenuItem.DropDownItems["Copy"].PerformClick();
}
else if (e.KeyData == (Keys.Control | Keys.V))
{
this.editToolStripMenuItem.DropDownItems["Paste"].PerformClick();
}
else if (e.KeyData == (Keys.Control | Keys.A))
{
this.selectToolStripMenuItem.DropDownItems["Select All"].PerformClick();
}
}
}