Are there some static method which can help?
Asked
Active
Viewed 592 times
2 Answers
0
The Control.Controls proeprty will return all child controls of the given control, but not the entire tree of child controls. But it's not hard to write a method that returns all child controls. If you are on .NET 3.5 you can use Linq to do it quite easily:
var allChildControls = control.Controls.OfType<Control>().SelectMany(c => c.Controls.OfType<Control>());

Rune Grimstad
- 35,612
- 10
- 61
- 76
-
As a side note. I needed to filter the Controls collection using OfType
. I thought this wasn't necessary since the collection only returned Control objects. Does anybody know why this is needed? – Rune Grimstad Aug 06 '09 at 08:39
0
I know you said without explicit recursion, however, I thought this answer was neat. Nothing special except for the use of the yield keyword.