DataGridView KeyDown事件不起作用 [英] DataGridView KeyDown Event not working

查看:260
本文介绍了DataGridView KeyDown事件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有KeyDown事件的DataGridView。

I have a DataGridView with a KeyDown event.

void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.C && e.Modifiers == (Keys.Control | Keys.Shift)) 
    {     
        MessageBox.Show("ok"); // to test if working
    }
}

消息框提示何时我按了组合键。

但这仅在datagridview为空(没有数据行)时。
当datagridview已经有行时,该代码不起作用。

The message box prompts when I press the key combinations.
But that is only when the datagridview is empty (no rows of data). The code doesn't work when the datagridview has rows already.

代码是否有错误?

推荐答案

当DataGridView处于编辑模式时, KeyDown 事件处理程序不会触发。

The KeyDown event handler doesn't fire when the DataGridView is in edit mode.

这篇关于DataGridView KeyDown事件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆