本文介绍了防止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 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屋!
更多推荐
[db:关键词]
发布评论