Samuel Toh

Samuel Toh

  • NA
  • 106
  • 14.4k

Delete Rows that does not contain the value that I want.

Oct 27 2021 2:37 AM

for (int i = 0; i < applicationDataGridView.Rows.Count; i++)
            {
                string[] Jobs = { "Network Engineer", "Financial Analyst", "Accountant", "Payroll Administrator", "Accountant Manager", "Sales Consultant" };

                if (!applicationDataGridView.Rows[i].IsNewRow)
                {
                    if (applicationDataGridView[4, i].Value.ToString() != Jobs)
                    {
                        applicationDataGridView.Rows.RemoveAt(i);
                        i--;
                    }
                }  
            }

 

Above is the code that I have tried but It does not work. I want to delete the rows that doesn't contain the values in "Jobs" which I have assigned as a string. The Job column is column "4".


Answers (13)