FROM#/. NET how to highlight specific rows in a DataGridView

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?

+6
c # winforms datasource datagridview
source share
3 answers

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.

+7
source share

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; } } 
+1
source share

You can use RowPrePaint to change the color or style of the entire string.

+1
source share

All Articles