执行对输入按键代码块我们正试图在datagridviewcell
编辑在enter key press
执行的代码块mode.But我们无法找到editing mode
上datagridviewcell
输入按键。在DataGridViewCell的
回答
你将不得不使用dataGridView1_KeyDown
事件如下:
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.SuppressKeyPress=true;
//block of code
}
}
的KeyDown不会在编辑模式下,子类的DataGridView单元工作,覆盖ProcessDialogKey这样。
protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData == Keys.Enter)
{
// Your code here
return true;
}
return base.ProcessDialogKey(keyData);
}
先生我们要做的是,在按下输入单元格中的键1执行代码块1,然后在单元格2中按回车键执行代码块2等等。什么block1的代码是它会显示一个包含listview的模式框。 – user2541238
我已经向你展示了如何拦截回车键,添加你的代码来显示我指出的对话框。 – Gary
@ user2541238您必须引用'CurrentCell'属性来确定哪个单元处于编辑模式以相应地执行您的代码。 –
如果要检查正在单击哪个单元格,请执行下列操作。这是在VB.net中。扩展Gary已经建议你的东西。
公共类Custom_DataGridView 继承System.Windows.Forms.DataGridView
公共事件DataGridView_CustomEnterKeyPressed(BYVAL KEYDATA作为键,BYVAL CurrentCell作为的DataGridViewCell)
受保护的覆盖功能ProcessDialogKey(BYVAL KEYDATA作为键)为布尔 如果keyData = Keys.Enter Then RaiseEvent DataGridView_CustomEnterKeyPressed(keyData,CType(Me,DataGridView).CurrentCell) '返回true'如果您不想移动到下一个单元格,请打开此项,如果您打开此选项,光标将不会转移到n列中的外部单元格。 结束如果 返回MyBase.ProcessDialogKey(KEYDATA) 端功能
末级
使用此Custom_DataGridView而不是开箱DataGridView控件,然后你必须处理DataGridView_CustomEnterKeyPressed事件在您的形式显示在下面您在其中添加了此自定义控件。
私人小组DataGridNameYouHaveUsed_DataGridView_CustomEnterKeyPressed(BYVAL KEYDATA作为System.Windows.Forms.Keys,BYVAL CurrentCell作为DataGridViewCell的)把手DataGridNameYouHaveUsed.DataGridView_CustomEnterKeyPressed MSGBOX( “以DataGridView_CustomEnterKeyPressed事件处理程序单元(:” + CurrentCell.ColumnIndex.ToString +”, “+ CurrentCell.RowIndex.ToString +‘)’) 结束小组
您可能已经解决了您的问题,只是张贴这样,如果别人(像我)正在寻找一个解决方案,这可能是对他们有用。
- 1. 的DataGridViewCell在asp.net
- 2. 在DataGridViewCell的
- 3. 全选在DataGridViewCell中
- 4. DataGridViewCell Bordercolor
- 5. sendkeys.send( “{RIGHT}”)中的DataGridViewCell
- 6. DataGridViewCell中的图像
- 7. DataGridViewCell PaintErrorIcon方法
- 8. DataGridViewCell事件序列
- 9. 需要自定义的DataGridViewCell
- 10. datagridviewcell下的打开表格
- 11. 多的DataGridViewCell在编辑模式下
- 12. 在自定义DataGridViewCell中承载UserControl
- 13. 在创建时更改DataGridViewCell BG颜色
- 14. 在DataGridViewCell中捕获KeyUp事件
- 15. DataGridViewCell值为空,而实际上存在
- 16. 的DataGridViewCell的风格不更新时间
- 17. 设置DataGridViewCell的错误图标位置
- 18. 如何处理DataGridViewCell中的KeyEvent?
- 19. 如何将DataGridViewCell的转换为控制
- 20. 如何使datagridviewcell的默认值为空
- 21. 用户控件中的DataGridViewCell WPF
- 22. 我该如何测试DataGridViewCell的类型?
- 23. 限制DataGridViewCell中的字符数
- 24. 将自定义控件添加到DataGridViewCell
- 25. C#更改DataGridViewCell值不起作用
- 26. 将属性添加到单个DatagridViewCell
- 27. 编辑DataGridViewCell,但没有ObservableCollection作为ItemsSource
- 28. 使用DataViewRowState将样式分配给DataGridViewCell
- 29. 以编程方式专注于DataGridViewCell
- 30. 制作自定义DataGridViewCell只读
在哪里执行代码 – user2541238
里面如果条件 –
它也可以在datagridviewcell编辑模式下工作。 – user2541238