Click here to Skip to main content
15,885,546 members
Articles / Desktop Programming / Windows Forms

Change individual DataGridView row colors based on column value

Rate me:
Please Sign up or sign in to vote.
3.76/5 (17 votes)
8 Jan 2010CPOL 168.5K   19  
Below is an example of changing the individual row colors based on one of the DataGridView's columns.While this is not hard to do, the property isn't always where you think it should be, its hidden within the rows DefaultCellStyle property.Here's the example:foreach (DataGridViewRow...

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
8 Jan 2010dwilliss
Another way to do something like this is to handle the RowPrePaint event and change the background there. The advantage to doing it this way is that if you have thousands of rows, you don't have to set it for every row at the beginning, which could take a few seconds. This way only sets it for...
Please Sign up or sign in to vote.
4 Aug 2011Lakhan Aanjana
If cell color is depend on criteriaif (ca.con.State == ConnectionState.Closed) { ca.con.Open(); } string qry = "select * From productmaster "; SqlDataAdapter da = new SqlDataAdapter(qry, ca.con); DataSet ds1 =...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Osiris Trading
South Africa South Africa
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions