如何处理在的DataGridViewCell的KeyEvent? [英] How to handle KeyEvents in a DataGridViewCell?

查看:172
本文介绍了如何处理在的DataGridViewCell的KeyEvent?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个的DataGridViewCell ?结果
我想要一个的keydown 事件做的是,当用户在一个特定信元输入时,他可以按下F1该特定列的帮助。有的形成会弹出...

Is there a Keydown Event of a DataGridViewCell?
What I'm trying to do is when a user is typing in a particular cell, he can press F1 for help of that particular column. And some Form will popup...

这是什么?

推荐答案

我发现代码在一个论坛,和它的作品。

I found this code in a forum, and it works.

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
  DataGridViewTextBoxEditingControl tb =(DataGridViewTextBoxEditingControl)e.Control;
  tb.KeyPress += new KeyPressEventHandler(dataGridViewTextBox_KeyPress);

  e.Control.KeyPress += new KeyPressEventHandler(dataGridViewTextBox_KeyPress);
}


private void dataGridViewTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
  //when i press enter,bellow code never run?
  if (e.KeyChar==(char)Keys.Enter)
  {
    MessageBox.Show("You press Enter");
  }
}

这篇关于如何处理在的DataGridViewCell的KeyEvent?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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