The best thing to do would probably be to create an array list to hold the references:
Code:
System.Collections.ArrayList arlTextBoxes = new ArrayList();
arlTextBoxes.Add(TextBox1);
arlTextBoxes.Add(TextBox2);
arlTextBoxes.Add(TextBox3);
...
foreach (TextBox txt in arl) {
//Your loop code here
}
You could use an array in the above code if you know the number of textboxes up front.
You could also use the control collection of your form but all your textboxes will have to be directly on the form and not in any container controls like panels or tabs. This also assumes that you want to loop through ALL of the textboxes on the form:
Code:
foreach (Control ctl in this.Controls) {
if (ctl is TextBox) {
TextBox txt = (TextBox) ctl;
//Your loop code here
}
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.