I have 5 error provider controls in my form which correspond to 5 text boxes, I am trying to loop through each text box and perform some validation on it such as if the text box is empty.
If a textbox is empty I would like the corresponding error provider control to display an error message, however I am having trouble when it comes to how to increment the errorprovider, such as errorProvider[count] where count would get incremented after each validation loop.
private void ValidateForm(){
int count = 1;
foreach (TextBox tb in this.Controls.OfType<TextBox>()){
if(string.IsNullOrWhiteSpace(tb.Text)){
errorProvider1.SetError(tb, "Please enter a value");
//errorProvider[count].SetError(tb, "Please enter a value");
}
count ++;
}
}