473,394 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Find Child Control

Hello,

I have a control named Parent in my page.
Parent has many child controls under it which also have other child
controls under them.

I need to find a control named "A" which i don't know exactly where it
is.
I just know that is under parent or under any of Parent Child
controls ...

How can I do this?

Thanks,
Miguel
Jan 27 '08 #1
2 2278
trival:

// find all child controls named "A"

Control[] list = ControlWalker(myControl, delegate(Control ctl)
{
return ctl.ID != null && ctl.ID == "A";
});

......

// control walker method

public delegate bool ControlWalkerMatcher (Control ctl);
public Control[] ControlWalker(
Control ctl,
ControlWalkerMatcher matcher)
{
ArrayList list = new ArrayList();
if (matcher(ctl)) list.Add(ctl);
for (int i=0; i < ctl.Controls.Count; ++i)
{
Control[] childList =ControlWalker(ctl.Controls[i],matcher);
if (childList.Length 0) list.AddRange(childList);
}
return (Control[]) list.ToArray(typeof(Control));
}

-- bruce (sqlwork.com)

shapper wrote:
Hello,

I have a control named Parent in my page.
Parent has many child controls under it which also have other child
controls under them.

I need to find a control named "A" which i don't know exactly where it
is.
I just know that is under parent or under any of Parent Child
controls ...

How can I do this?

Thanks,
Miguel
Jan 27 '08 #2
On Jan 27, 1:01 am, bruce barker <nos...@nospam.comwrote:
trival:

// find all child controls named "A"

Control[] list = ControlWalker(myControl, delegate(Control ctl)
{
return ctl.ID != null && ctl.ID == "A";
});

......

// control walker method

public delegate bool ControlWalkerMatcher (Control ctl);
public Control[] ControlWalker(
Control ctl,
ControlWalkerMatcher matcher)
{
ArrayList list = new ArrayList();
if (matcher(ctl)) list.Add(ctl);
for (int i=0; i < ctl.Controls.Count; ++i)
{
Control[] childList =ControlWalker(ctl.Controls[i],matcher);
if (childList.Length 0) list.AddRange(childList);
}
return (Control[]) list.ToArray(typeof(Control));
}

-- bruce (sqlwork.com)

shapper wrote:
Hello,
I have a control named Parent in my page.
Parent has many child controls under it which also have other child
controls under them.
I need to find a control named "A" which i don't know exactly where it
is.
I just know that is under parent or under any of Parent Child
controls ...
How can I do this?
Thanks,
Miguel
Hi,

Your code is a little bit confusing to me. Why a delegate?
Can't a single function perform the action of searching for the
control?

Thanks,
Miguel
Jan 29 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tia Carr | last post by:
When I try to place a child control on top of a panel control, the mouse pointer remains as a pointer instead of changing to a cross. I tried both the ShowGrid on/off, doesn't make a difference.....
3
by: Arulraja | last post by:
Hello, I have created 2 custom server controls, The parent custom control contains multiple child custom controls. The Child control has a button on it. If I Click the button control, it...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
0
by: Bruin | last post by:
Hi All, I'm having a problem with MDI child forms when the reference to the MDI Parent is set in a Control library. (Sorry for the long post) I have an control library assembly which holds all...
0
by: Qwert | last post by:
Heya, I have a user control (inherits from listview control). I add a textbox control to it as a child control and give the child control the focus. All is well when I type text (keyboard input)...
3
by: Jon Paal | last post by:
i have a textbox control inside a custom server control that needs to be prefilled with content. how do i find this child control ? <ew:cp id="ccp2" TitleText="" runat="server">...
7
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent...
1
by: shapper | last post by:
Hello, I have a custom control, MyCustomControl, with a property named Childs of type Generic.List(Of MyChildControl). I added a MyCustomControl to my page and added a few MyChildControls to...
2
by: Bob Johnson | last post by:
..NET 3.5: I have placed two controls at the top of an Mdi parent form. The top-most control is a Panel that is docked to the Top. Immediately below the Panel is a user control that is Anchored to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.