I have an instance of a treeview, with 4 sets of nodes. They are nested and are (from parent to child...):
Company --> Department --> Location --> WorkEquipment
Selecting any one of these opens a form in an adjacent window (see code below). Right now, once the form is open it stays open and is just covered up by the next one. The app needs to close the open form when another node is selected. Do I need to write some sort of destructor, or use a Form.Unload type of command? Thanks.
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
Dim NewMDIChild As New Form
If TreeView1.SelectedNode.Tag = "company" Then
NewMDIChild = New frmCompany
ElseIf TreeView1.SelectedNode.Tag = "department" Then
NewMDIChild = New frmDepartment
'Give the passed node
ElseIf TreeView1.SelectedNode.Tag = "location" Then
NewMDIChild = New frmLocation
ElseIf TreeView1.SelectedNode.Tag = "we" Then
NewMDIChild = New frmWorkEquipment
gstrPassedNode = TreeView1.SelectedNode.Text
'Set the Parent Form of the Child window.
NewMDIChild.MdiParent = Me
'Display the new form.