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 872081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:43:55+00:00 2026-05-15T10:43:55+00:00

I am attempting to show a specific form using a treeview control, the nodes

  • 0

I am attempting to show a specific form using a treeview control, the nodes of which have their tag value set to an instance of the Form I need to show. The code I have in the DoubleClick event works great for the first time I show a form, but after that I get an object disposed exception. As you can see, I tried handling it by resetting the tag, but that didn’t work. Is there any way I can show the form more than once without going through a switch statement anytime the exception comes up and resetting the tag to the right type of form? I’d like something nicer looking like the way I show the form.

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim fm2 As New Form2()
        Dim fm3 As New Form3()
        TreeView1.Nodes(0).Tag = fm2
        TreeView1.Nodes(1).Tag = fm3
    End Sub

    Private Sub TreeView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.DoubleClick
        Try
            CType(TreeView1.SelectedNode.Tag, Form).Show()
        Catch odex As ObjectDisposedException
            TreeView1.SelectedNode.Tag = New Form()
            TreeView1_DoubleClick(sender, e)
        Catch nrex As NullReferenceException
            'No node selected, do nothing.  
        End Try
    End Sub
End Class
  • 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-15T10:43:55+00:00Added an answer on May 15, 2026 at 10:43 am

    Your problem here is if the user closes the form, the object will have been disposed.

    There are a few ways you can handle this, some more elegant than the other.

    1. Add a handler for FormX_Closed() at this time you can reset the tag reference
    2. You could switch to a “Show dialog” process and then reset before your DoubleClick() method ends

    It really depends on what these forms are doing. Typically i would see your DoubleClick method doing a lookup then creating the instance, simply because if you create instances you are using memory that might not be needed, but that is something that might be necessary considering your application.

    Lookup Example

    As requested in the comments, if I were to do this a different way, I would use an enumeration value, or even a simple integer “key” value for the tag. Then I would create something like the following to show it.

    Select Case myTag
        Case 1
            Dim formInstance As New Form1()
            formInstance.Show()
        Case Else
            Dim formInstance As New Form2()
            formInstance.Show()
    End Select
    

    Basically centralize it and launch the form on demand, you could switch this out for another design pattern if you wanted more control or had a lot of different form types.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 545k
  • Answers 545k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • added an answer Well, start off by thinking of which bits of data… May 17, 2026 at 9:17 am
  • added an answer For this task it is a good idea to use… May 17, 2026 at 9:15 am
  • added an answer This is exactly how the Skyhook database (built into many… May 17, 2026 at 9:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.