Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 数据网格上的IsLetter键控事件_C#_Wpf_Datagrid_Char_Keydown - Fatal编程技术网

C# 数据网格上的IsLetter键控事件

C# 数据网格上的IsLetter键控事件,c#,wpf,datagrid,char,keydown,C#,Wpf,Datagrid,Char,Keydown,我试图通过计算用户输入是字母还是数字,将用户输入分解为DataGrid上的KeyDown事件。这是我目前使用的方法 private void OnDataGridKeyDown(object sender, KeyEventArgs e) { if (char.IsLetter(Convert.ToChar(e.Key))) { MessageBox.Show("Letter"); } if (char.IsDigit(Convert.ToChar

我试图通过计算用户输入是字母还是数字,将用户输入分解为DataGrid上的KeyDown事件。这是我目前使用的方法

private void OnDataGridKeyDown(object sender, KeyEventArgs e)
{
    if (char.IsLetter(Convert.ToChar(e.Key)))
    {
        MessageBox.Show("Letter");
    }
    if (char.IsDigit(Convert.ToChar(e.Key)))
    {
        MessageBox.Show("Number");
    }
}

然而,这表现得很奇怪。首先,IsDigit从未发生过,而且显然不起作用。其次,Isleter可以工作,但只对某些字母(W、Z、X、V和Y)起作用。必须有一个更全面的方法来做这件事,因为这显然对我不起作用。

key.toChar()
char
之间有区别,你希望它们在那里。您可以在此处阅读有关转换的内容,但这并不简单:


你应该记录
Convert.ToChar(e.Key))
@thomas ayoub添加了如何在当前环境中使用它为什么要重新实现
char.islitter()
char.IsDigit()
当它已经存在并且运行良好时?你说得对,兄弟,这个问题中还有另一个问题
char.islitter(Convert.ToChar(Key.A))=>true
这应该可以,如果OP没有更多信息,就没有办法提供帮助。这里的主要问题是,他捕获的事件是键盘事件,并且该键实际上是一个键而不是一个字符。例如,键入shift-A时,您将收到两个事件,而不是按键时的一个事件。