Solved

Best way to loop thru controls on a form recursively?

Posted on 2014-04-10
2
407 Views
Last Modified: 2014-04-11
What is the most efficient way to loop thru all the controls on a form including controls within container controls?

Thanks!
0
Comment
Question by:BlakeMcKenna
2 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
Comment Utility
	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
 

Author Closing Comment

by:BlakeMcKenna
Comment Utility
Thanks James...exactly what I was looking for!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now