winform程度中的GridView如何禁使用回车键。 winform程度中的GridView如何禁使用回车键。在gridview中点击回车键后焦点自动从当前单元格跳到下面的单元格中,这个回车键的作用能屏蔽掉吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 KeyPress事件中if(e.KeyChar==(char)Keys.Enter){ e.Handled=true;} //在KeyPress事件里写 if (e.KeyChar == (char)Keys.Enter) { e.Handled = true; } 不好意思,是我没有说清楚。我想实现的功能是这样的。例如:焦点所在的单元格所在的行是1,这时候点击回车键触发KeyPress事件。在事件中我需要获取事件发生单元格的行列坐标,但是由于点击回车键后自动跳到了下一行。所以获得的行坐标总是+1,是个错误坐标。而且最后一个和倒数第二行获得的坐标是一样的。所以我需要禁用点击回车键跳到下一下的功能。 //在KeyPress事件里写 if (e.KeyChar == (char)Keys.Enter) { e.Handled = true; //在这里获取坐标 } 看下面的可以吗? private void dataGridView1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == 13) { e.Handled = true; } } keypress事件是在点击之后执行.故应放在keydown事件下来写 private void dataGridView1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == 13) { e.Handled = true; } }up完全正确 楼主,试试下面代码,是你要的效果。加引用(Accessibility),重写事件(ProcessCmdKey)protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData){ if (msg.WParam.ToInt32() == (int)Keys.Enter && this.ActiveControl.AccessibilityObject.ToString().Contains("DataGridView")) { MessageBox.Show(dataGridView1.CurrentCell.RowIndex.ToString() + "," + dataGridView1.CurrentCell.ColumnIndex.ToString()); //如果需要Enter事件,写到这里... return true; } return base.ProcessCmdKey(ref msg, keyData);} form 类如何阻塞线程 C# 动态调用java webservice的问题?? 新手,VS2010如何编译,运行文件,英文看不懂 寻解 C# 求5元矩阵…… 为控件设置输入焦点有什么用? 麻烦告诉我一下什么函数能把字符串中前面的0去掉???谢谢 各路高手来指点一下 c#DataGridView CellEndEdit方法中怎样获取键盘输入 急问题:Form之间如何调用并传递数据? C#窗体传值,大神帮忙看看呗 C++找字符串中字母后面的数转C#?? 求你了 扇我脸吧
if(e.KeyChar==(char)Keys.Enter)
{
e.Handled=true;
}
//在KeyPress事件里写
if (e.KeyChar == (char)Keys.Enter)
{
e.Handled = true;
}
例如:焦点所在的单元格所在的行是1,这时候点击回车键触发KeyPress事件。在事件中我需要获取事件发生单元格的行列坐标,但是由于点击回车键后自动跳到了下一行。所以获得的行坐标总是+1,是个错误坐标。
而且最后一个和倒数第二行获得的坐标是一样的。所以我需要禁用点击回车键跳到下一下的功能。
//在KeyPress事件里写
if (e.KeyChar == (char)Keys.Enter)
{
e.Handled = true;
//在这里获取坐标
}
{
if (e.KeyValue == 13)
{
e.Handled = true;
}
}
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
e.Handled = true;
} }up
完全正确
加引用(Accessibility),重写事件(ProcessCmdKey)
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
if (msg.WParam.ToInt32() == (int)Keys.Enter && this.ActiveControl.AccessibilityObject.ToString().Contains("DataGridView"))
{
MessageBox.Show(dataGridView1.CurrentCell.RowIndex.ToString() + "," + dataGridView1.CurrentCell.ColumnIndex.ToString());
//如果需要Enter事件,写到这里...
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}