在比较DataGridView的单元格新旧价值新旧、单元格、价值、DataGridView

由网友(薄凉小伙)分享简介:如何更改基于新的单元格的值是否>或其中的DataGridView细胞前景色;比现有/旧单元格的值?有没有这通过改变目前的新前值的事件,这样我就可以比较它们? How to change DataGridView cell ForeColor based on whether new cell value is > o...

如何更改基于新的单元格的值是否>或其中的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.

阅读全文

相关推荐

最新文章