Setting a property for a cast form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If I want to open a form and pass a parameter, I would usually say:

private frm as new frmMyForm
frm.CustNumber = 123

However, I've created a generic procedure to open the form based on the class name:
frm = DirectCast(Activator.CreateInstance(Type.GetType("MyApp." & strClassName)), Form)

How do I set a custom property of the form using the above syntax?

Thanks,
Denise
 
Hi

You can use the reflection for this again.

Dim MyType As Type = Type.GetType("MyApp." & strClassName)
Dim Mypropertyinfo As PropertyInfo = MyType.GetProperty("CustNumber")
Mypropertyinfo.SetValue(Myproperty, "This CustNumber has been changed.", _
Nothing)

frm = DirectCast(Activator.CreateInstance(MyType),Form)

PM Soraj
Micorosft India Community Star
 
Hi

You can use the reflection for this again.

Dim MyType As Type = Type.GetType("MyApp." & strClassName)
Dim Mypropertyinfo As PropertyInfo = MyType.GetProperty("CustNumber")
Mypropertyinfo.SetValue(Myproperty, "This CustNumber has been changed.", _
Nothing)

frm = DirectCast(Activator.CreateInstance(MyType),Form)

PM Soraj
Micorosft India Community Star
 
Thanks - that's just what I needed!

Sooraj PM said:
Hi

You can use the reflection for this again.

Dim MyType As Type = Type.GetType("MyApp." & strClassName)
Dim Mypropertyinfo As PropertyInfo = MyType.GetProperty("CustNumber")
Mypropertyinfo.SetValue(Myproperty, "This CustNumber has been changed.", _
Nothing)

frm = DirectCast(Activator.CreateInstance(MyType),Form)

PM Soraj
Micorosft India Community Star
 
Back
Top