Reference all controls in a container control

Is there anyway (that I’m missing!) to reference all of the controls in a container control?

For example if I have a container called containercontrol1 that contains 5 text fields that I want to enable and disable depending on whether the user is allowed to input into them at that particular time I’d like to be able to do something along the lines of containercontrol1.allcontrols.enabled = false

At the moment I’m having to type txtFirstname.enabled = false txtLastname.enabled = false etc etc which is time consuming.

Thank you in advance for your answers.

a simple way is a computed property where you place your controls in the set method

[code]Public Property EnableAll as Boolean
Get

End Get

Set
TextField1.Enabled = value
TextField1.Enabled = value

End Set

End Property
[/code]

Hello Markus, thank you for your reply. I’ll take a look at computer properties as I don’t know anything about them.

@Rod Pascoe — For your immediate concern, all the controls would be enabled/disabled if the ContainerControl itself is enabled/disabled so you don’t have to set the state for all the controls.

Stphane you are amazing! Thank you so much, this does exactly what I want it to do.

I knew somebody a lot cleverer than I am would know that answer, thank you again.

Here is how you access all controls in the Container Control. Works the same in a window.

[code]Sub Pressed() Handles Pressed

for c as integer = 0 to self.ControlCount-1
system.debuglog self.Control©.Name
next

End Sub
[/code]

for Textboxes the ReadOnly Property is better, so you can select and copy the text in this textbox.
disable will not allow to put a cursor in it.

[quote=460993:@Michel Bujardet]Here is how you access all controls in the Container Control. Works the same in a window.

[code]Sub Pressed() Handles Pressed

for c as integer = 0 to self.ControlCount-1
system.debuglog self.Control©.Name
next

End Sub
[/code][/quote]

There are some very clever people on this forum!

[quote=460996:@Markus Rauch]for Textboxes the ReadOnly Property is better, so you can select and copy the text in this textbox.
disable will not allow to put a cursor in it.[/quote]

Thanks Markus, for this particular use case then disabled is required but I do get what you mean.