how can I loop through each control on a form and populate...

supermanzdead

Active member
Joined
Feb 23, 2006
Messages
31
Programming Experience
Beginner
I am loading a form that is popuplated by infromation from a text file (list of computers), anyway right now i have the form getting the ip address and everything onload, i would rather have a load button on the toolbar that people can hit to load all the information about items on a tab page.

Anyway, my question is how can I loop through each control on a form and populate the text field or text labels??
 
Well to loop through all the controls on a form, including container controls..

VB.NET:
Dim Crtl as control = me.getnextcontrol(me,true)
while not ctrl is nothing
If ctrl.gettype is gettype(textbox) then
Add your logic for populating the controls.
end if
me.getnextcontrol(ctrl,true)
end while
 
Here is an alternate method, but it will not search containers of the controls collection processed.
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] l [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Label
[/SIZE][SIZE=2][COLOR=#0000ff]For [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] c [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Control [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] TabPage1.Controls
[/SIZE][SIZE=2][COLOR=#0000ff]  If [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]TypeOf[/COLOR][/SIZE][SIZE=2] c [/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] Label [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]    l = [/SIZE][SIZE=2][COLOR=#0000ff]DirectCast[/COLOR][/SIZE][SIZE=2](c, Label)
[/SIZE][SIZE=2][COLOR=#008000]    '...
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]  End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE]
 
Back
Top