防止Windows窗体datagridview在单元格编辑之后更改行 [英] Prevent windows forms datagridview to change row after cell edit
本文介绍了防止Windows窗体datagridview在单元格编辑之后更改行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Windows窗体中有一个datagridview,当编辑值是编辑单元格后的默认行为,当我按回车键,所选行将更改为下一个。
I have a datagridview in windows forms, the default behavior when editing values is that after the edition of a cell, when I press enter, the selected row changes to the next.
I不想要,我想退出编辑模式,但是保持在同一个单元格。
I don't want that, I want to exit edit mode but staying in the same cell.
可以吗?
推荐答案
您可以自定义 DataGridView
以覆盖 ProcessDialogKey
方法:
You can customize the DataGridView
to override the ProcessDialogKey
method:
public class CustomGrid : DataGridView {
protected override bool ProcessDialogKey(Keys keyData) {
if (keyData == Keys.Enter) {
EndEdit();
return true;
}
return base.ProcessDialogKey(keyData);
}
}
这篇关于防止Windows窗体datagridview在单元格编辑之后更改行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文