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

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

问题描述

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



弹出菜单当DataGridView中选定的行发生更改时,状态将被更新,并且当弹出菜单更改时,DGV所选行中的状态将更新。



除了,当我更改弹出菜单的值时,DataGridView中的行不会立即更新。我必须选择不同的行才能看到我的修改。



我假设这是因为在选择更改之前编辑尚未提交。我的问题是:如何使弹出窗口的更改立即反映在DataGridView中?



我有尝试在弹出式菜单的SelectionChangeCommitted处理程序中调用EndEdit(),但这没有任何效果。我感兴趣的一个技术,将允许我创建一个DataGridView,就像没有Undo机制一样开始。理想情况下,解决方案将是通用的,可移植到其他项目。

解决方案

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



感谢大家的回应。


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

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.

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.

My question is: How do I make the change to the popup become immediately reflected in the 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.

解决方案

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.

Thanks to everyone for your responses.

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

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