我找到了答案,这要归功于varocarbas,他在下面评论我的原始问题。我的假设是CellEndEdit事件在ProcessCmdKeys()方法调用之后的某个地方被触发,但由于ENTER键的优先级高于普通键(它是Command键),所以在OnKeyPress()调用之前。这就解释了为什么当一个单元格仍处于使用OnKeyPress()的EditMode中时,我无法改变行为。
,我创建的自定义的DataGridView,防止任何行动发生之后在一个DataGridView的ENTER键按下,可以在下面看到:
Public Class clsModifyDataGridView
Inherits Windows.Forms.DataGridView
''' <summary>
''' Changes the behavior in response to a Command-precedence key press
''' </summary>
''' <returns>True if we handled the key-press, otherwise dependent on default behavior</returns>
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
' Was the ENTER key pressed?
If keyData = Keys.Enter Then ' YES
' DO NOTHING
Return True
End If
' Handle all other keys as usual
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
End Class
有人如果请大家指正我的假设成立呼叫序列不足。还要注意,这个ProcessCmdKey()覆盖使得我之前提到的OnKeyPress()方法的覆盖是不必要的。
恐怕你必须解释编辑模式中发生的事情的唯一方法是挂钩键(尽管没有让你完全控制这种情况的事件)。在这里你有一篇文章(在C#中)链接到似乎是这个问题的解决方案:http://stackoverflow.com/questions/2527371/how-can-i-change-what-happens-when-enter- key-is-press-on-a-datagridview – varocarbas
谢谢,使用你的链接我找到了我正在寻找的答案! –
我很高兴得到了帮助。 – varocarbas