I’m having trouble with TreeView when opening a form from clicking on a child node, then closing that form (the FormClosed event does have Me.Close() and Me.Dispose() in it). The problem accrues after collapsing the parent node, the previous form opens again. The form is open from Treeview AfterSelect event.
Private Sub TreeView1_AfterSelect(sender As Object, e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
Dim rc%, i%
Dim daFoodCat As New OleDbDataAdapter("Select * FROM tblFoodCategories INNER JOIN tblRecipes " & _
"ON tblFoodCategories.RecipeID = tblRecipes.RecipeID " & _
"ORDER BY RecipeName", cn)
Dim dsRecipeName As DataSet = New DataSet
daFoodCat.Fill(dsRecipeName, "tblFoodCategories")
rc = dsRecipeName.Tables(0).Rows.Count
For i = 0 To rc - 1
If dsRecipeName.Tables(0).Rows(i).Item("RecipeName") = e.Node.Text Then
rcpID = dsRecipeName.Tables(0).Rows(i).Item("tblRecipes.RecipeID")
End If
Next
If rcpID = 0 Then
'Do nothing
Else
frmRecipes.ShowDialog()
End If
End Sub