c# - 如何处理 DataGridViewCell 中的 KeyEvents?

标签 c# winforms datagridview

是否有 DataGridViewCellKeydown 事件?
我想要做的是,当用户在特定单元格中键入内容时,他可以按 F1 键以获得该特定列的帮助。并且会弹出一些表单...

这是什么事件?

最佳答案

我找到了 this在论坛中编写代码,并且有效。

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");
   }
}

关于c# - 如何处理 DataGridViewCell 中的 KeyEvents?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3697517/

相关文章:

c# - DataGridView 组合框列 : Change cell value after selection from dropdown is made?

c# - 应用程序日志记录 Azure Web 应用程序的最佳实践?

c# - GridView 排序升序不起作用

c# - Json.NET 忽略字典中的空值

c# - Double 的蒙面文本框?

c# - 截图工具滞后荧光笔

c# - 从 dataGridView 到 TextBox,取 headername

c# - 委托(delegate)参数中的 Co(ntra) 方差

c# - WinForms:无需转到 FormWindowState.Normal 即可找到最小化表单的大小

c# - DataGridViewCombBoxColumn 单元格值和不同的下拉列表