基于行的数据更新的DataGridView单元格背景颜色 [英] Update DatagridView Cell Background color based on row data

查看:177
本文介绍了基于行的数据更新的DataGridView单元格背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个DataGridView,我想它改变背景颜色取决于各行中的数据。

Hi I got a DatagridView and I would like it to change background color depending on the data in each row.

例。

|人1 |人2 |人3 |

| Person 1 | Person 2 | Person 3 |

| ---- 100 ---- | --- 200 ----- | ----- 150 ---- |

|----100----|---200-----|-----150----|

| ---- 300 ---- | --- 100 ----- | ------ 50 ---- |

|----300----|---100-----|------50----|

在第一行,我想它使100有一个红色的背景色和200的绿色。 要么。最低值=红色最高=绿色

In the first row I would like it to make "100" have a red background color and "200" green. Or. The lowest value = red highest = green

现在的事情是,即时通讯使用的BindingList我的数据,其更新异步与INotifyPropertyChanged的。所以,我需要检查的一个值已经更新,每次的一些方法。

Now the thing is that Im using a BindingList for my data, and its being updated async with INotifyPropertyChanged. So I need some way of checking each time one of the values has been updated.

不要在DataGridView有任何情况下,这将是有用的?

Do the DataGridView have any event that would be usefull?

推荐答案

子类的DataGridView,并覆盖OnCellFormating(),在这里你可以检查单元格的值,并设置适当的颜色。

Subclass DataGridView and override OnCellFormating(), in here you can inspect the cell value and set the colours appropriately.

在考虑到下面的评论有关使用相应的事件,是的,你可以这样做,但虚方法具有更好的性能和子类的DataGridView封装在一个地方网格的所有行为。

In regard to comments below about using the corresponding event, yes you can do that but the virtual method has better performance and subclassing DataGridView encapsulates all the behavior of your grid in one place.

这篇关于基于行的数据更新的DataGridView单元格背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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