如何运行运行CellEndEdit只有当细胞的valueChanged中的DataGridView [英] How to run Run CellEndEdit only when Cell ValueChanged in DataGridView

查看:175
本文介绍了如何运行运行CellEndEdit只有当细胞的valueChanged中的DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想只运行CellEndEdit当单元格的值发生改变,试图把

i want to run CellEndEdit only when value of cell is changed, tried putting

if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == e.FormattedValue.ToString()) 
             return; 

在CellValidation事件,该单元格验证事件不会回来,但CellEndEdit也被执行和更新,更新日期&放大器; 字段,当用户只已经进入编辑模式就出来了,而不改变值单元格。
到时候CellEndEdit达到 CellValue &放大器; 格式化值是相同的,所以不能把这个CellEndEdit。

in CellValidation event, the Cell Validation event does return but CellEndEdit also gets executed and updates, updated date & by fields when the user has only gone into edit mode and came out without changing the value cell.
By the time CellEndEdit is reached CellValue & Formatted Value are same so couldn't put this in CellEndEdit.

一个平凡的解决办法是设置一个标志CellValidation并返回CellEndEdit时,标志设置,但是这似乎是一个容易出错的解决方案,因为有窗体上约10 girds。因此,10标志?

A trivial solution is to set a flag in CellValidation and return CellEndEdit when flag is set, but this appears to be a error-prone solution as there are about 10 girds on the form. So 10 flags?

推荐答案

而不是执行的任务CellEndEdit的,把它们放在CellValueChanged。它只是在发射单元格值发生改变。请注意,它会火最初填充你的DataGridViews的时候,却来处理,你可以把只有一个变量说formInitialized什么,以确保你不执行你的CellEndEdit当你填入你的数据网格。

Instead of performing your tasks in CellEndEdit, put them in CellValueChanged. It is fired only when cell value is changed. Please note that it will fire when your DataGridViews are initially populated, but to handle that, you can put just one variable saying formInitialized or something, to make sure that you are not executing your CellEndEdit when you populate your data grids.

和回答你的问题,有没有办法找出如果当CellEndEdit被触发值被改变,因为它在细胞失控的编辑模式总是被解雇。唯一的解决办法是,像你这样的建议,在外部存储旧值,但你已经注意到了,为什么是坏的(虽然它的作品真的很好,在大多数的情况下)。

And to answer your question, there is no way to figure out if value is changed when CellEndEdit is fired, because it is always fired when cell gets out of edit mode. The only solution is, like you proposed, to store the old value externally, but you already noticed why is that bad (though it works really good in most of the cases).

这篇关于如何运行运行CellEndEdit只有当细胞的valueChanged中的DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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