Looping through components on a form

Glitterati

Member
Joined
Mar 17, 2006
Messages
13
Programming Experience
Beginner
I have a form with multiple instances of a component on it. I want to be able to loop through all the components and return the information to an arraylist. Is this possible?

Thanks!
 
It's kind of cheesy, but I have a "guest" class which I turned into a component. The component holds information about guests that have visited a particular website. There are multiple instances of this component and I want to loop through each of the instances and populate a text file with the information. Hope that makes more sense. Thanks!
 
Glitterati, you'll need to post the class file so kulrom and/or i can help you go about getting all the info
 
This should work..... obiously you will need to translate it a bit


dostuffto (me)

sub dostuffto controls(parentcontrol as control)
for each c as control in parentcontrol.controls

dostuffto(c)

if gettype(c) is myspecialusercontrol then
do my thing
end if
next
end sub
 
I guess what's giving me the most trouble is looping through each instance of the component. I've tried putting:

dim arrGuests as ArrayList = New ArrayList
dim MyGuest as new Guest

For each MyGuest in Form1
arrGuests.Add(MyGuest)
Next

This gives me an error: Form is a type and not a collection. This is where is all falls apart on me. I'm sure I"m making this harder than it needs to be. :)
 
VB.NET:
For Each ctl As Control In Me.Controls
  If TypeOf ctl Is Guest Then
    'Its your control, do stuff
  End If
Next Ctl
 
Back
Top