0

Are there some static method which can help?

rudnev
  • 2,281
  • 3
  • 22
  • 31

2 Answers2

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.

https://stackoverflow.com/a/277654/645283

Community
  • 1
  • 1
VFein
  • 1,021
  • 2
  • 11
  • 23