I have a DataGridView that is populated by setting a DataSource to a DataBinding.
Now I want to have certain rows in the DataGridView having different Backgroundcolor according to some value in the row itself.
How can i do this?
Here is a great example here.
The concept is that you are subscribing to events from the grid. When a cell is full, the event is fired and is based on a value that you can format the cell, etc.
In the CellFormatting event handler of your datagridview, you can set the default background color for any desired row.
private void MyDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.RowIndex == rowIndexToHighlight) { e.CellStyle.BackColor = Color.Green; } }
You can use RowPrePaint to change the color or style of the entire string.