IS there a quick and easy way to get all controls on a form?
Printable View
IS there a quick and easy way to get all controls on a form?
form.controls?
The form.controls only returns the controls that the form is parent of, it won't return child controls on that control.
The answer is I don't know if there is an easy way(would like to know one though!) At present I think you need to create a custom collection and add each control to it. See the post on text box controls for the code, which is around here somewhere.
Ok i might be naive here but im not sure which are parent/child controls. I want to get a list of all (let's say) command buttons that are on the form? Are these children? Or will form.controls work?Quote:
Originally posted by cim3
The form.controls only returns the controls that the form is parent of, it won't return child controls on that control.
The answer is I don't know if there is an easy way(would like to know one though!) At present I think you need to create a custom collection and add each control to it. See the post on text box controls for the code, which is around here somewhere.
My inclination is that it woudl work but i'm not near my computer
Why couldn't you loop through all controls on the form and examine each one and check to see if it has anything in *its* Controls collection?
If the button is on the form itself not on a tabcontrol or another control that is on the form then Me.Controls will work for you. I agree with Slow_Learner just use recursion. I guess you are going to have to change your name soon Slow_Learner ;)
How can I take a name like Captain Wiseass when I neglect to note that all Controls have a HasChildren property?
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsformscontrolclasshaschildrentopic.htm
thanks though :D
Quote:
Originally posted by Slow_Learner
Why couldn't you loop through all controls on the form and examine each one and check to see if it has anything in *its* Controls collection?
I was not talking about the technique here, i simply needed to knwo if a form.controls woudl return a list with (for example command buttons) in it. I woudl obviously loop to find the exact one i needed. the haschildren was key, thanks.
thanks though guys.