Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Posted

@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.

Posted
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) ?
Posted

@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.

  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...