Question how to expose methods and properties of user controls contained in a collection?

theAsocialApe

Member
Joined
Mar 21, 2008
Messages
13
Programming Experience
5-10
I'm stumped here.
I've got a user control with one to infinity minus 1 instances of another user control in it.

at some points, I need to call the same method on those controls (ex. user presses the clear button on the big control, I want to call the clear f(x) on each of the controls)

I thought to toss the controls in a collection, and then be able to handle them something like this:
VB.NET:
for each c as control in myControlCollection
   c.clear()
next

turns out, and I should have realized, methods and properties of controls are not exposed when treated this way. The only thing that can be seen is the stuff that the base class (control, I guess) has.

I know there's always other ways to attack a problem, and I could figure something else out, but if this is an acceptable way to approach this, I'd like to go at via a collection of my controls.
 
Use CType or DirectCast to type cast an instance to the type you want to see it as. Compare types with TypeOf/GetType if needed.

You can also if possible use more type specific collections/lists using generics, for example if all the control instances is of T Type or derived from you can use a List(Of T) or derive from Collection(Of T).
 
ga! I know that. Or I did. Then I totally forgot or something. I spent all afternoon trying to figure out that (of T) stuff [which for some reason (my nuibbitude, no doubt)] always confuses me.

Thanks much!
 
Back
Top