views:

304

answers:

1

my project is written in c#. I have a usercontrol that I've designed. In that usercontrol I want the ability to look through the form the control is placed on using reflection to look at all other controls on the form.

How can I go about doing this? I've used reflection to go through dll's but not for something like this.

in summary: My usercontrol is placed on a form, I want my usercontrol to onLoad look through all other controls on the form (sometimes i'll want to limit it to same container and not entire form but I can figure that out later).

I'm also open to ideas that dont use reflection if anyone has any.

thanks!

EDIT:

So i tried simply looking through the parent controls and that didnt work for what im trying to do, which is my fault for badly explaining it above.

Let me give some more details.

I know that on the main form there will be a ContainerListView control, now when you add columns to the containerlistview ContainerListviewColumnHeaders's are created. Their declarations show up in the initalizeComponent() for the form. What I want to do is in my usercontrol I want to look at the form and find all of the ContainerListViewColumnHeader's, however since they are not of type 'Control' (they are 'Component') they dont show up in the previous method. Interrogating the Containerlistview is not an option.

+5  A: 

No need for reflection.

Just look at UserControl.ParentForm - this is the Form that's hosting the UserControl. From there, you can iterate (recursively) through Form.Controls.

Reed Copsey
+1 ...beat me by a couple seconds.
Justin Niessner
Edited my description to give more information
Without Me It Just Aweso