find string in DataGridView
        Posted  
        
            by LCountee
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by LCountee
        
        
        
        Published on 2010-05-07T19:32:05Z
        Indexed on 
            2010/05/07
            19:48 UTC
        
        
        Read the original article
        Hit count: 391
        
I'm using a foreach loop to populate each row in a DataGridView with a string. I need to search the DataGridView to make sure that I don't add a string that is already there. What is the best way to do this?
Here is my code so far:
foreach (String file in openFileDialog.FileNames)
    {                                    
        // todo: make sure file string does not already exist in DataGridView
        dataGridView1.Rows.Add();
        dataGridView1.Rows[i].Cells[1].Value = file;
        i++;
    }
        © Stack Overflow or respective owner