简体   繁体   English

如何在c#dataGridView中的单元格编辑后抑制行更改?

[英]How to suppress row change after cell edit in c# dataGridView?

After changing value in cell and pressing enter cursor jumps down to next cell. 更改单元格中的值并按enter光标会跳至下一个单元格。 Is it possible to avoid this behavior? 是否可以避免这种行为? I want to make cursor stay at same cell after edition accomplishment. 我想使光标在版本完成后停留在同一单元格。 I use CellEndEdit to perform some action with value in cell. 我使用CellEndEdit对单元格中的值执行一些操作。
Thanks! 谢谢!

您可以通过按keypress事件或cellvaluechanged事件找到enter键来限制它

After all I solved my problem in following lame way. 毕竟,我以following 脚的方式解决了我的问题。
1. Add global boolean flag to detect if I need to jump up after edit and set it to false . 1.添加全局布尔值标志以检测是否需要在编辑后跳起来并将其设置为false
2. In CellEndEdit event handler set flag to true . 2.在CellEndEdit事件处理程序中,将标志设置为true
3. In SelectionChanged event handler check flag. 3.在SelectionChanged事件处理程序中,选中标志。 If it set to true then jump up and set flag to false . 如果将其设置为true则跳转并设置flag为false
4. Set AllowUserToAddRows to false to avoid adding row in case of last row cell edition. 4.将AllowUserToAddRows设置为false以避免在最后一行单元格版本的情况下添加行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM