470,632 Members | 2,057 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,632 developers. It's quick & easy.

Dynamically loading controls -> loosing type

Hi NG

We want to load controls dynamically and create them on a WinForm. Doing so,
we seem to loose type information. The scenario is as follows: The class
MANCombobBox inherits from ComboBox and implements the interface
IReportDataSource.

This works:
Control c = new MANComboBox(); //MANComboBox inherits from ComboBox and
implements the interface IReportDataSource

MessageBox.Show( (c is IReportDataSource).ToString() ); //This
returns/displays true

Here we have the problem:
Assembly asm = Assembly.LoadFile("LookupControls.dll"); //loads the dll
which contains the MANComboBox control

Control control = (Control) asm.CreateInstance(fullControlName); //Pointing
with the mouse onto control, the IDE tells me, that control contains
something of type MANComboBox

MessageBox.Show( (control is
MAN.Framework.Win.MANReportLookupControls.MANCombo Box).ToString() );
//returns false

Intellisense even shows me the methods of the implemented interface
IReportDataSource but during runtime an invalid cast exception is thrown.

Any hints?

Thanks for all the help we get

Cheers

Peter
Jul 21 '05 #1
0 1001

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by kanones | last post: by
3 posts views Thread by supvine | last post: by
2 posts views Thread by nemesis.saurabh | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.