Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Can someone please provide some code to itterate through EVERY control in a form? I know how to do the basic one

 

for each control in me.controls
next

 

but how do you handle container controls with controls inside of them? What about container controls inside of container controls? Is there a simple an easy way to do this?

 

Phylum

  • *Experts*
Posted
If you wanted to set the text of all controls on a form, you'd do something like this:
    Private Function SetAllTextProperties(ByVal textVal As String, ByVal rootContainer As Control)
       Dim c As Control

       For Each c In rootContainer.Controls
           c.Text = textVal
           SetAllTextProperties(textVal, c)
       Next
   End Function

and use it like

SetAllTextProperties("test", Me)

Remember that all controls have a controls collection (even if they aren't container controls), so you still check every control on the form for children.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...