Click here to Skip to main content
14,828,290 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have tried below code but. it sets red color to all rows in grid view, please help???

What I have tried:

C#
private void DevideDuplicate()
        {

            string WID = txtWeaver.Text, QCODE = cbQualityCode.Text; //WID for Worker ID and QCODE is for Quality Code

                foreach (DataGridViewRow row in dgCal.Rows)
                {
                    if (WID == row.Cells[0].Value.ToString() && QCODE == row.Cells[2].Value.ToString())
                    {
                        row.DefaultCellStyle.BackColor = Color.Red;
                    }
                }

        }
Posted
Updated 22-Mar-19 10:00am
v2

1 solution

The simplest solution is to use the DataGridView.RowPrePaint Event[^] - it's very similar to the CellPainting event I use here: Colouring DataGridView Cells According to their Content in WinForms[^]
   
Comments
Maciej Los 22-Mar-19 16:01pm
   
5ed!

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