防止windows窗体datagridview在单元格编辑后更改行

编程入门 行业动态 更新时间:2024-10-27 12:30:46
本文介绍了防止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:关键词]

本文发布于:2023-03-29 10:28:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/753645.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗体   单元格   编辑   windows   datagridview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!