Check if a dataGridView has errorText set on any of it's cells
c#, datagridview, winforms
Solution
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;
}
Problem
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