Getting usercontrol from string
G'day all,
I've got the following situation: I have a basic usercontrol. All my other user controls inherit from that control. Let say: usrBasic, and usrRelations inherits usrBasic, so does usrProducts and so on.
I want to load usrRelations onto a form. The only thing I've got is its string with the type, let's say: "Consultic.UserControls.usrRelations"
Does anyone know how to load this usercontrol on a windows form? Setting properties like anchor and so on isn't the problem, purely loading the usercontrol onto the form when only knowing its type...
Thanx in advance,
Marco
Re: Getting usercontrol from string
Re: Getting usercontrol from string
this one?
if not sorry.
VB Code:
me.Controls.Add(Consultic.UserControls.usrRelations)
Re: Getting usercontrol from string
Quote:
Originally Posted by heuyen
this one?
if not sorry.
VB Code:
me.Controls.Add(Consultic.UserControls.usrRelations)
No, in your example "Consultic.UserControls.usrRelations" is the STRING value I have, I need to know how to create an instance of this usercontrol from this string value. This value comes from a database, so I need to do it dynamically...
Re: Getting usercontrol from string
Well, after searching a lot, I've found out:
VB Code:
Dim ty As Type = Type.GetType("CodeBase.usrCodeBase", True)
Dim o As System.Windows.Forms.Control = CType(Activator.CreateInstance(ty), Control)