Hey,
I have Control, which may have child controls. These child controls can have other child controls and so on.
How to find parent control of specified child control?
Findcontrol() doesn't search for child controls.
Regards in advance
Printable View
Hey,
I have Control, which may have child controls. These child controls can have other child controls and so on.
How to find parent control of specified child control?
Findcontrol() doesn't search for child controls.
Regards in advance
.ParentQuote:
Originally posted by Norkis
How to find parent control of specified child control?
Yes, I know that, but how to find that control if it is child control in another child control etc.?
Presumably you would know what the ultimate parent control is - like your form. Do a loop on parent until you get to the form name.
Can you give sample of doing this?
Code:private void FindParents(object sender)
{
// cast control of interest to generic control object
Control ctl=(Control)sender;
// loop until the parent control == form name (or whatever ultimate parent control you're interested in
while(ctl.Parent.Name!=this.Name)
{
System.Diagnostics.Trace.WriteLine(ctl.Parent.Name.ToString());
// make the current control the parent of the last tested control
ctl=ctl.Parent;
}
}
I tryied to convert this code to vb at http://www.developerfusion.com/utili...tocsharp.aspx, but I got error An error occured while processing your code: -- line 2 col 14: invalid VariableDeclarator.
What's the problem?
Your functions finds all parent controls if child control is specified.
But how to find child control if I only know the main parent control?
Like I said I have control, which has child controls, and those child controls have their child controls and so on.
How to find child control if I only know main control's name, which is holding other controls?