Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 834169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:38:04+00:00 2026-05-15T04:38:04+00:00

I am attempting to launch a specific form depending on the selected node of

  • 0

I am attempting to launch a specific form depending on the selected node of a treeview on the doubleclick event. The code I need to use to launch the form is a little bulky becuase I have to ensure that the form is not disposed, and that the form is not already open, before launching a new instance. I’d like to have all of this checking happen in one place at the end of the function, which means that I have to be able to pass the right form type to the code at the end. I’m trying to do this with a System.Type, but that doesn’t seem to be working. Could someone point me in the right direction, please?

    With TreeView.SelectedNode
        Dim formType As Type
        Select Case .Text
            Case "Email to VPs"
                formType = EmailForm.GetType()
            Case "Revise Replacers"
                formType = DedicatedReplacerForm.GetType()
            Case "Start Email"
                formType = EmailForm.GetType()
        End Select
        Dim form As formType
         Dim form As formType
        Try
            form = CType(.Tag, formType)
            If Not form.IsDisposed Then
                form.Activate()
                Exit Sub
            End If
        Catch ex As NullReferenceException
            'This will error out the first time it is run as the form has not yet 
            ' been defined.
        End Try
        form = New formType
        form.MdiParent = Me
        .Tag = form
        CType(TreeView.SelectedNode.Tag, Form).Show()
    End With
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:38:05+00:00Added an answer on May 15, 2026 at 4:38 am

    You can’t new a Type. The Type is a runtime-type information, new needs to know the type at compile time.

    Use either reflection (Activator) or generics.

    Sorry I don’t know VB, I can’t give you a code example in VB.

    c# example:

    T CreateForm<T>() where T : Form, new()
    {
      return new T();
    }
    

    or

    Form CreateForm(Type t)
    {
      return (Form)Activator.CreateInstance(t);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am attempting to launch an intent to open a link to the android
I am attempting to write a python daemon that will launch at boot. The
Attempting to use the data series from this example no longer passes the JSONLint
Attempting to use XStream's JavaBeanConverter and running into an issue. Most likely I'm missng
I have created a menu using a treeview to launch forms when the user
I'm attempting to launch an instance of the VideoLAN program from within a java
I am trying to use the gtm-oauth kit (http://code.google.com/p/gtm-oauth/wiki/GTMOAuthIntroduction) for OAuth2. As instructed by
I am attempting to launch the built-in camera to take a picture, a picture
In my app I'm attempting to use the front camera by default in a
I am trying to find file associations before attempting to launch the file, the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.