简体   繁体   中英

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

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;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM