比较 DataGridView 单元格中的新旧值 [英] Compare old and new value in DataGridView cell

查看:22
本文介绍了比较 DataGridView 单元格中的新旧值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据新单元格值是> 还是<来更改DataGridView 单元格ForeColor比当前/旧单元格值?是否有事件在更改电流之前传递新值,以便我可以比较它们?

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屋!

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