Question
3
Replies
25
Views
CenturyLink
Posted: November 17, 2020
Last activity: November 20, 2020
RDA - WinForm - How to reliably iterate through all controls under parent WinForm (Or select controls of specific type)
I've run into an issue where attempting to loop recursively down the child controls from a top-level WinForm will miss certain controls, namely TreeViews. If I add a panel as the first child of the WinForm, then recursively loop through all the controls of the WinForm AND the first-child Panel, all controls are reached. @jeffbadger, is there a better way to do this?
Thanks,
Matthew Ashley
Matt,
I would write a recursive method that you can call that takes in a generic control. Every control has a property called Controls. This is an array of child controls. If your control has any children, they would be in this array. You might also have grandchildren and great grandchildren, so making a method that you can call recursively would be best. I don't have an example, but perhaps if you share your script, I could tweak it.