3

I'm using the Forms.Controls.Find Method to search the child controls of a parent control. The method has 2 arguments; (Key, SearchAllChildren). I know that the Key argument does a string comparison on the child controls' names and fills the return array with the controls that have a matching name. However, I do not know the significance of the SearchAllChildren argument.

The MSDN documentation says: true to search all child controls; otherwise, false. What does this mean? Won't it search all the child controls anyways? Is this to control whether the search is recursive? So if it's true then the search will go through the children of all the children and all the children of the children of the chilren and etc., but if false then it will only go through the first level of children?

Thanks,

Ian
  • 4,169
  • 3
  • 37
  • 62

1 Answers1

5

Controls.Find("name", false) will search for direct children only.

Controls.Find("name", true) will look for child controls and recursively search all child controls children, etc.

The docs for this method are really bad. I had to look at the search to be absolutely sure the difference.

Samuel Neff
  • 73,278
  • 17
  • 138
  • 182
  • 1
    Thankyou. I suppose the argument should be named SearchAllDescendents, or SearchChildrenRecursively. When it is false the method searches all children, when true it searches, children, grandchildren, great-grandchildren, and beyond. – Ian Jan 09 '13 at 16:27
  • @Ian, according to MS's own class library design guidelines, it really shouldn't be a boolean at all. It should be an enum like `FindControls.SearchDirectChildren` and `FindControls.SearchAllDescendants` or something similar. Unfortunately, once an API is made, it's a bit of a pain to change it. – Samuel Neff Jan 10 '13 at 04:32