Datagrid view conditional formatting

Welcome to Wisej Support.
Questions, suggestions and plain old bugs - are all welcome here!
0
0

Hi,

Is there any way that conditional formatting can be applied to the Datagridview rows?

Being able to change the background/foreground color as well as the font type/sizes etc based on a field meeting a specific value or range of values would be really handy.  A typical use case would be a grid full of employee records, with one of the fields in the employees table called active.  If active is false, then the row background color would be a dark gray, giving a visual cue to the user that this record is different to the others.

Another use case would be were an integer value like a stock level falls in between a range of values, like stock remaining between 1 and 4, then setting the background color of the row to a red, giving that same visual cue to the user that more stock needs to be ordered, and if the stock level is between 5 and 10, then the background color of the row would be yellow and above 10 then the background row color would be whatever the default color is set at.

  • You must to post comments
0
0

There are several ways to achieve that.

One is to handle the CellFormatting event and change the Style passed in the event args. Another approach is to handle CellValueChanged and set the Style of the other cell. You can also cache and reuse DataGridViewCellStyle objects.

I have attached a small sample that shows both approaches since it answers another similar question.

HTH

Best,

Luca

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Attachment
File Name Size
There are currently no files uploaded.
Maximum number of files 5, maximum file size 3.9MB.
Supported file formats: zip pdf gif jpg bmp png cs vb theme json