Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a dataGridView has errorText set on any of it's cells

How can I know if a datagridview has errorText on any of it's cells. I have a Save button which I want to enable only if all cell values are valid meaning that none of the cells have errorText set

like image 578
user271077 Avatar asked Mar 08 '10 10:03

user271077


1 Answers

Use this method on your code:

private bool HasErrorText()
    {
        bool hasErrorText = false;
        //replace this.dataGridView1 with the name of your datagridview control
        foreach (DataGridViewRow row in this.dataGridView1.Rows)
        {
            foreach (DataGridViewCell cell in row.Cells)
            {
                if (cell.ErrorText.Length > 0)
                {
                    hasErrorText = true;
                    break;
                }
            }
            if (hasErrorText)
                break;
        }

        return hasErrorText;
    }
like image 126
Jojo Sardez Avatar answered Sep 20 '22 01:09

Jojo Sardez