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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With