Check if the gridview data file is installed on any of its cells

How to find out if datagridview has an error code in any of its cells. I have a Save button that I want to enable only if all the cell values ​​are valid, that none of the cells has a set error set

+5
source share
1 answer

Use this method for 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;
    }
+10
source

All Articles