Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to hide the row if it has a certain word in it ....


foreach (DataGridViewRow dr in CustOrdersDGV.Rows)
{
    if (dr.Cells[6].Value.ToString() == "hot")
    {
        dr.Visible = false;
    }
}



But all of the cells show regardless

What I have tried:

<pre>                foreach (DataGridViewRow dr in CustOrdersDGV.Rows)
                {
                    if (dr.Cells.Count > 6)  // validate the index

                    if (dr.Rows[6].Value.ToString() == "hot")
                    {
                        dr.Visible = false;
                    }
                }
Posted
Updated 11-Apr-18 17:26pm

1 solution

You seem to investigate rows instead of cells in the if statement. Also you expect to the cell value to be exactly "hot", not just contain it. Try using
C#
if (dr.Cells[6].Value.ToString().ToLower().Contains("hot"))
{
   dr.Visible = false;
}
 
Share this answer
 

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