如何让 DataGridView 立即提交编辑? [英] How do I make a DataGridView immediately commit edits?

查看:46
本文介绍了如何让 DataGridView 立即提交编辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主从布局,其中包含一个弹出菜单部分(详细信息)和一个包含保存行的 DataGridView 的部分.

I have a master-detail layout with a section of popup menus (the Details) and a section with a DataGridView which holds the rows.

当 DataGridView 中的选定行发生更改时,弹出菜单状态会更新,而当弹出菜单更改时,DGV 选定行中的状态应更新.

The popup-menu state is updated when the selected row in the DataGridView changes and the state in the DGV's selected row should update when the popup-menu changes.

所有这些都有效除了DataGridView 中的行在我更改弹出菜单的值时不会立即更新.我必须选择不同的行才能看到我的编辑.

All of this works except the row in the DataGridView doesn't immediately update when I change the value of the popup-menu. I have to select a different row in order to see my edits.

我假设这是因为在选择更改之前编辑尚未提交.

I'm assuming this is because the edit hasn't been committed until the selection changes.

我的问题是:如何使对弹出窗口的更改立即反映在 DataGridView 中?

My question is: How do I make the change to the popup become immediately reflected in the DataGridView?

我曾尝试在弹出菜单的 SelectionChangeCommitted 处理程序中调用 EndEdit(),但这没有效果.我对一种技术感兴趣,它允许我创建一个 DataGridView,它的行为就好像没有撤消机制一样.理想情况下,该解决方案应该是通用的并且可以移植到其他项目中.

I have experimented with calling EndEdit() in the SelectionChangeCommitted handler for the popup-menu, but this has no effect. I'm interested in a technique that would allow me to create a DataGridView that would behave as if there were no Undo mechanism to begin with. Ideally the solution would be generic and transplantable to other projects.

推荐答案

这是发生了什么.答案在 ComboBox 实例的属性中.我需要将他们的 DataSourceUpdateModeOnValidation 更改为 OnPropertyChanged.这是有道理的.DataGridView 很可能显示数据的当前状态.只是数据还没有被编辑,因为焦点没有离开ComboBox,验证输入.

Here's what was going on. The answer was in the properties of the ComboBox instances. I needed to change their DataSourceUpdateMode from OnValidation to OnPropertyChanged. This makes sense. The DataGridView was very likely showing the current state of the data. It was just that the data hadn't been edited yet because focus had not left the ComboBox, validating the input.

感谢大家的回复.

这篇关于如何让 DataGridView 立即提交编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆