Setsuko Posted January 29, 2004 Posted January 29, 2004 Can anyone help me with this one, I'm all out of ideas :( I have a custom Component deriving from Component. This component also implements the IListSource interface. The most important method I have to implement for this is GetList(); In the GetList method I need to obtain the parents type where my component is placed on. In this case a standard form derived from System.Windows.Forms.Form. I tried to do the following: IDesignerHost host = Site.Container as System.ComponentModel.Design.IDesignerHost; With the host I have now, I can get the RootComponent, BUT, and now comes the problem, the RootComponent is at that time the baseclass of the actual parent object. So I get System.Windows.Forms.Form instead of my derived parent class' type. I've discovered that this is because the designerhost is at that moment still in the loading state. The problem is that the GetList() is called before the loading state finishes and by the time the host is fully loaded, it it already too late, GetList isn't called again. Can anyone help me with this ? I'll be worshipping you until the end of my days ;)customcomponent.cs Quote
NK2000 Posted January 30, 2004 Posted January 30, 2004 every control has a Parent member, which aims to the parental control :) Quote
Hamburger1984 Posted January 30, 2004 Posted January 30, 2004 uhm I understand that you're looking for a possibility to find a components parent - it tried to do so once too... ;) but what is the whole thing gonna be? I mean maybe it isn't even neccessary to get the parent that way in code but (for example) from a property. please provide a little bit more information....! Andreas Quote
Setsuko Posted February 2, 2004 Author Posted February 2, 2004 @NK2000: The Component doens't :( A component is not a control. --- I want to get the parent, my component is placed on, because I need its type. So for instance, I want to if'm i'm placed on Form1, instead of System.Windows.Forms.Form. Through this type I can get the assembly and return data based upon datatypes inside the assembly. This works great by using the RootComponent type of the DesignHost, BUT.... The designhost returns a different RootComponentType during loading than after it. The down side is that I need to now the correct type during loading, because this is also the time GetList is called (by the databindings on the form) on my component. Quote
NK2000 Posted February 2, 2004 Posted February 2, 2004 uhm maybe i havent enough experience for that, because i didnt work that much with forms, but why do you have to use a component, and not the control class (inherited from component) ? Quote
Administrators PlausiblyDamp Posted February 2, 2004 Administrators Posted February 2, 2004 Can you give an example of the code from the calling form? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Setsuko Posted February 4, 2004 Author Posted February 4, 2004 @NK2000: Because I don't need a control. My component doesn't offer anything visual. Still, I have to be able to set it's properties with the property palette. I'm trying to create a small test-case that illustrates the problem in a more simplified way. I'll post it later. Quote
*Gurus* divil Posted February 4, 2004 *Gurus* Posted February 4, 2004 You are using the correct way of obtaining an instance of the container your component is hosted on - rootComponent is always this container. It doesn't return a different object during the load state either - if you are designing a control that derives from Form, you will always get Form (or whatever the base class is) because the designer cannot instantiate a partially-designed class. So if your component is relying on the designed form actually being of a derived form type, you're out of luck - unless you have derived twice, in which case you'll get the first derivation being instantiated for the design surface. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.