How to choose multiple objects' same property?

equi

New member
Joined
Oct 26, 2012
Messages
1
Programming Experience
Beginner
Hi.
I am trying to make software which consists 128 textbox.
At the beginning, when the user fills all the textboxes and saves, all the textboxes' enable property should be false.
Is there a short way of doing this? Or should I write down textbox(X).enabled=false for 1 to 128?
Thanks..
 
First, 128 textboxes is really not ergonomic design, and I highly doubt you actually need that many...

If you insist on using all those 128 textboxes, then yeah a for-next loop is pretty much the way to go.
 
I agree with Herman that a form with 128 TextBoxes on it is probably not a great idea. That said, assuming that all those TextBoxes are on the same parent control and they are the only TextBoxes on that control:
VB.NET:
For Each tb In theParent.Controls.OfType(Of TextBox)()
    tb.Enabled = False
Next
or:
VB.NET:
Array.ForEach(theParent.Controls.OfType(Of TextBox)().ToArray(), Sub(tb) tb.Enabled = False)
 
Back
Top