Click here to Skip to main content
15,304,711 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

I had a datagrid in my application. I Want to check each row. If each row of a particular cell value contains same that particular cell values should be coloured and remaining unmatched cell value should another color.

Thanks in advance for your feedback.

CHill60 20-May-13 8:07am
What have you tried so far?
Kschuler 20-May-13 14:24pm
I've had DataGridViews that I set visibility=False until the page is done loading, but there are cetain things, such as cell backcolor, that you need to make sure the grid is visible before you set them. So watch out for that.

1 solution

private void ChangeColor(DataGrid dataGrid,string valueToComapre)
        for (var row = 1; row < dataGrid.Items.Count; row++)
            for (int col = 0; col < dataGrid.Columns.Count; col++)
                if (dataGrid.Items[row].Cells[col].Text == valueToComapre)
                    dataGrid.Items[row].Cells[col].BackColor = System.Drawing.Color.Green;
                    dataGrid.Items[row].Cells[col].BackColor = System.Drawing.Color.Red;


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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900