Validation of all Text Boxes

Asked

Viewed 23 times

0

Code:

if (this.Controls.OfType<TextBox>().Any(f => string.IsNullOrEmpty(f.Text)))
{
    MessageBox.Show("É necessario preencher todos os campos.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

This command was very useful for me, however I have only 1 text not to fill

Ex. Code of Registration

This text box will not be filled by the user, would have some command to leave it out?

1 answer

0

Add a condition to your Lambda

if (this.Controls.OfType<TextBox>().Any(f => f.Name != "txtCodCadastro" && string.IsNullOrEmpty(f.Text)))
{
    MessageBox.Show("É necessario preencher todos os campos.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.