[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

Best way to loop thru controls on a form recursively?

What is the most efficient way to loop thru all the controls on a form including controls within container controls?

Thanks!
0
BlakeMcKenna
Asked:
BlakeMcKenna
1 Solution
 
Jacques Bourgeois (James Burger)Commented:
	Public Sub LoopThroughControls(container As Control)

		For Each ctl As Control In container.Controls
			'Do your stuff here...
			If ctl.Controls.Count > 0 Then
				LoopThroughControls(ctl)
			End If
			'... or here
		Next

	End Sub

Open in new window

A form is a Control, so you can send your form to that method, and it will recursively calls itself back when you encounter a Control that contains other Controls.
0
 
BlakeMcKennaAuthor Commented:
Thanks James...exactly what I was looking for!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now