I have a form with a number of controls on it, and I had thought that the "Controls" property of the form instance contained all of the controls on the form as per the documentation.

Actually it does, but now iterating over all of my controls becomes similar to iterating over all the files in a directory structure, recursing subdirectories (groupboxes are now like folders).

So.. is there a generic algorithm for this in the standard library?

It could be a time saver knowing of this when using lots of nested groupboxes, btw.

6 Years
Discussion Span
Last Post by darkagn

Each Control has a Parent attribute, so you could use something like the following Linq statement to get just the "top-most" controls.

var controls = this.Controls.Where(o => o.Parent.Equals(this));
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.