在比较DataGridView的单元格新旧价值 [英] Compare old and new value in DataGridView cell
问题描述
如何更改基于新的单元格的值是否>或其中的DataGridView细胞前景色;比现有/旧单元格的值?有没有这通过改变目前的新前值的事件,这样我就可以比较它们?
How to change DataGridView cell ForeColor based on whether new cell value is > or < than current/old cell value? Is there an event which passes the new value before the current is changed, so I can compare them?
的数据从底层源更新,并且可以通过BindingSource的约束。
The data is updated from underlying source, and may be bound by BindingSource.
推荐答案
我遇到了类似的问题。我使用 CellValidating
事件,而不是解决这样的:
I ran into a similar issue. I tackled this by using the CellValidating
event instead:
void dgv_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
var oldValue = dgv[e.ColumnIndex, e.RowIndex].Value;
var newValue = e.FormattedValue;
}
当然,我只需要访问旧的价值,我不需要进行任何格式。我敢肯定,你可以将通过此事件处理程序的格式,虽然。
Admittedly, I just needed access to the old value, I didn't need to perform any formatting. I'm sure you can apply formatting through this event handler, though.
这篇关于在比较DataGridView的单元格新旧价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!