|
-
Jun 9th, 2004, 08:21 AM
#1
Thread Starter
Hyperactive Member
Controls & Child Controls
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
-
Jun 9th, 2004, 09:11 AM
#2
Fanatic Member
Re: Controls & Child Controls
Originally posted by Norkis
How to find parent control of specified child control?
.Parent
-
Jun 9th, 2004, 09:28 AM
#3
Thread Starter
Hyperactive Member
Yes, I know that, but how to find that control if it is child control in another child control etc.?
-
Jun 9th, 2004, 09:31 AM
#4
Fanatic Member
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.
-
Jun 9th, 2004, 09:33 AM
#5
Thread Starter
Hyperactive Member
Can you give sample of doing this?
-
Jun 9th, 2004, 10:05 AM
#6
Fanatic Member
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;
}
}
-
Jun 10th, 2004, 01:20 AM
#7
Thread Starter
Hyperactive Member
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?
-
Jun 10th, 2004, 07:00 AM
#8
Thread Starter
Hyperactive Member
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|