Link to home
Start Free TrialLog in
Avatar of spendergrass
spendergrass

asked on

How do I pass in variable and use it to open form in VB.NET application?

I have a VB.NET 2.0 WinForms application.  I have a procedure called LoadForm that allows me to pass in the parent form, child form name, and form caption and it opens up the child form within an MDI Container.

    Private Sub LoadForm(ByVal objParentForm As Object, ByVal strChildForm As String, ByVal strCaption As String)

        Dim typChildForm As Type = Type.GetType(strChildForm)
        Dim frmChildForm As Form = CType(Activator.CreateInstance(typChildForm), Form)

        frmChildForm.Text = strCaption
        frmChildForm.MdiParent = CType(objParentForm, Form)
        frmChildForm.WindowState = FormWindowState.Maximized
        frmChildForm.Show()

    End Sub

I would like to be able to pass in a primary key and open the form with the appropriate record.  Does anyone have an idea how I can update my procedure to allow me to pass in a primary key value and then use it on the form_load event to populate the form?

Thanks,
Sarah
ASKER CERTIFIED SOLUTION
Avatar of ororiole
ororiole
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of spendergrass
spendergrass

ASKER

If I don't cast the typChildForm to a Form I get the error: Option Strict On disallows implicit conversion from 'Object' to 'System.Windows.Forms.Form'.
It's working!  Thanks for your help!