如何让我的控件在 DataGridView 关闭我的控件之前检测到 Escape 键?
我有一个具有撤消功能的控件,当用户按 Escape 时,控件将恢复原始值。
问题是当我将控件集成到 DataGridView 时。 DataGridView“吃掉”了 Escape 键,因此我的控件无法检测到 Escape 键。
当我在 EditingControlWantsInputKey 上设置“return true”时,我的控件能够检测到 Escape 键,但出现了其他问题,DataGridView 无法关闭我的控件,它停留在 EditMode 中。
如何允许我的控件检测 Escape 键,同时允许 DataGridView 关闭我的控件?
I have a control with an undo feature, when the user press Escape the control will revert the original value.
The problem is when I integrated my control to DataGridView. The DataGridView "eats" the Escape key, hence my control cannot detect the Escape key.
When I put "return true" on EditingControlWantsInputKey, my control was able to detect the Escape key, but other problem arised, the DataGridView cannot close my control, it stays in EditMode.
How to allow my control to detect the Escape key while also allowing the DataGridView to close my control?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我能够解决我自己的问题。 我将 LookupBox 的 Undo 方法公开,然后在我的 DataGridView 控件(类 DgvLookupBoxEditingControl : LookupBox, IDataGridViewEditingControl)上,放置以下代码:
I was able to solved my own problem. I made the Undo method of my LookupBox public, then on my DataGridView control (class DgvLookupBoxEditingControl : LookupBox, IDataGridViewEditingControl), I put the following code:
仅当 Keys.KeyCode == Keys.Escape 时才应“返回 true”;
否则返回
!dataGridViewWantsInputKey。
You should "return true" only when Keys.KeyCode == Keys.Escape;
otherwise return
!dataGridViewWantsInputKey.
或者您可以将 PreviewKeyDown 处理程序添加到编辑控件并在那里检测 Escape。
Or you can add PreviewKeyDown handler to your editing control and detect Escape there.