Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a lot of TextBoxes in my form and need to change Text of them using For i = 0... etc.
I started from(found somewhere)
VB
Dim arrText As New ArrayList
arrText.Add(_Text1_0)
arrText.Add(_Text1_1)
arrText.Add(_Text1_2)
arrText.Add(_Text1_3)

But it's wrong direction, because I can't access to TextBoxes.
Please help.
Posted

Hello,

Both Windows Form Class and ASP.Net Page class have Controls collection. You can enumerate this to find your text boxes. More help can be found in following MSDN documents

Regards,
 
Share this answer
 
Comments
MegaSinner 5-Jun-13 7:33am    
There's no useful examples
Prasad Khandekar 5-Jun-13 7:36am    
Hello,

You can find an example for ASp.NET here (http://dotnetguts.blogspot.in/2008/11/finding-all-controls-on-page-in-aspnet.html). Similar concepts can be applied to Windows Forms.
MegaSinner 5-Jun-13 7:42am    
I can't convert it to VB. Searched over the net and found no anything useful. In C# it can be done in few lines, stupid basic(
Quote:
But it's wrong direction, because I can't access to TextBoxes.
No that is in a good direction. Probably you are bad implementing the suggestion. Please check (or post here) your actual code.

Solution 1, also, is good. Moreover documentation do provide useful examples, you have just to be a more careful reader.
 
Share this answer
 
Comments
MegaSinner 5-Jun-13 8:12am    
There is no clear practical application of "how to make array of EXISTENT texboxes and access to their properties"
CPallini 5-Jun-13 8:30am    
I the code YOU posted, the ArrayLIst is built using EXISTING text boxes. You may access tetxboxes properties just using the corrensponding array item, e.g. arrText(2).Text= "Foo". Do you need fries with it?
MegaSinner 5-Jun-13 11:09am    
Already solved. And in vbasic need to use '( )' instead '[ ]'
CPallini 5-Jun-13 11:17am    
You are right, fixed now.
VB
Dim Ctr() As Control = {_Text1_0, _Text1_1, _Text1_2, _Text1_3, _Text1_4, _Text1_5}

For i = 0 To Ctr.Length - 1
    Ctr(i).Text = "Text from FOR"
Next

Was hard to find it.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 9-Aug-13 11:02am    
No, you are not creating array of text boxes, you are using available ones, and this is no good.
You really need to create and insert them. What would you need to find? How to call a constructor?
(Insertion is done via myControl.Parent = ...).

It's a shame that you self-accepted this "answer". This is just fake...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900