I have a DataGridView that is filled by setting its 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 possibly accomplish this?
There's a great example here.
The concept is that you subscribe to events from the grid. When a cell is filled, an event is fired and based upon the value you can format the cell etc.
You can use the RowPrePaint to change the color or style of the whole row
In the CellFormatting event handler of your datagridview you can set the default backcolor for any row you want.
private void MyDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.RowIndex == rowIndexToHighlight)
{
e.CellStyle.BackColor = Color.Green;
}
}
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