代码之家  ›  专栏  ›  技术社区  ›  user271077

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

  •  5
  • user271077  · 技术社区  · 15 年前

    1 回复  |  直到 13 年前
        1
  •  12
  •   Jojo Sardez    15 年前

    对代码使用此方法:

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