简体   繁体   English

检查dataGridView是否在其任何单元格上设置了errorText

[英]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. 如何知道datagridview是否在其任何单元格上都有errorText。 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 我有一个Save按钮,只有当所有单元格值都有效意味着没有任何单元格设置了errorText时,我才想启用它

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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