简体   繁体   English

按键事件转到DataGridview而不是单元格

[英]Keypress event goes to the DataGridview instead of a cell

I have a DataGridView inside of the winform with delete event handled from toolstrip menu which delete the selected row (along with the object associated with that row in the DataGridView ). 我在winform有一个DataGridView ,它具有从toolstrip menu处理的delete事件,该toolstrip menu删除了选定的行(以及与DataGridView中与该row关联的对象)。

Now when i try to edit the value of any cell (to rename the object) , and in the edit mode if i select some characters and press delete , it delete the row instead of deleting those selected characters. 现在,当我尝试编辑任何cell的值(以重命名对象)时 ,并且在编辑模式下,如果我选择了一些字符并按delete键,它将删除该行,而不是删除那些选定的字符。

What should i do to make the cell handle the event rather than the Winform . 我应该怎么做才能使单元处理事件而不是Winform

snippets below: 以下代码段:

this.deleteToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Delete;

this.deleteToolStripMenuItem.Click += new System.EventHandler(this.OnDelete);

private void OnDelete(object sender, EventArgs e)
{
}

尝试检查您的DataGridView SelectionMode的属性,不得为FullRowSelect

Found a solution :) when i enter into edit mode i remove the delete key association 找到了解决方法:)当我进入编辑模式时,我删除了删除键关联

this.deleteToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.None; this.deleteToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.None;

and once i am done editing the cell in the OnAfterEdit i set it back to 当我在OnAfterEdit中完成单元格的编辑后,将其设置为

this.deleteToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Delete; this.deleteToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Delete;

Hope it helps someone. 希望它可以帮助某人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM