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