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

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

问题描述

有没有一个 Keydown $ code> DataGridViewCell 的事件?

我正在尝试要做的是当用户在特定的单元格中键入时,他可以按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天全站免登陆