Hi I got a DatagridView and I would like it to change background color depending on the data in each row.
Ex.
| Person 1 | Person 2 | Person 3 |
|----100----|---200-----|-----150----|
|----300----|---100-----|------50----|
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
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.
Do the DataGridView have any event that would be usefull?
Subclass DataGridView and override OnCellFormating(), in here you can inspect the cell value and set the colours appropriately.
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.
Not too sure if this is the optimal solution but hope it helps: Register for the PropertyChanged event for each data source item in the datagrid view. In your event handler, you can perform the required action based on the changed values.
If you are using a binding list for your datasource, register for ListChanged to handle new items.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With