prevent窗口窗体DataGridView单元格编辑后更改的行窗体、单元格、窗口、编辑

2023-09-04 00:12:29 作者:你的剧本我只是观众

我有一个DataGridView Windows窗体,默认的行为,当值的编辑是一个小区,当我preSS进入,所选择的行更改到下一个。

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