Friday, August 18, 2006

Getting parent

I have a control embedded in another nested control.

I need to get a parent several levels up (but not all the way up), basically I need to do a recursive search up the parents until I hit a parent that is one of two types - then I want to know which of the two types it was.

I haven't figured out how to do this: it seems that the Parent property of Control is unreliable - sometimes it sets itself, othertimes it is null. I am using ContainerControls so I tried the ParentForm property but this jumps me up all the way to my application form (further up the ancestory tree than I want to go). There is also Form.Owner but my control is not a form.

Right now, I am just manually setting my own propetry as I create each control ( I have to do this for a few different controls along the ancestory line)

No comments: