Validation of all Text box

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, but I have only 1 text not to fill

Ex. Registration Code

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

    
asked by anonymous 12.05.2018 / 23:20

1 answer

0

Add a condition in 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);
}
    
13.05.2018 / 11:50