Use this method for your code:
private bool HasErrorText()
{
bool hasErrorText = false;
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;
}
source
share