Hi Rod,
I haven't received a reply the last few times I've posted. If it is not too much trouble, am stumped again and would appreciate your valuable help. I am working with an application that involves an hierarchical list. I am able to generate one and two level lists but I am having trouble with three and possibly four levels. I have entered the code for level one, level two and level three node creations.
Level one Node creation takes the contents of TextBox1 and creates a Root level Node in TreeView1.
Level Two Node Creation take the contents of TextBox2 and creates a Root level Node under the root level node that is selected.
However, Level Three Node Creation acts differently. Although it takes the contents of TextBox3 and places it under the selected (second level) node. it causes the Second level Node to change to a Root level Node.
How can I add the third level Node without knocking both the second and third level nodes back down to Root and Second level nodes
Code:
Public Class CreateIndex
'Create a Root Level Node
Private Sub btnLevelOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLevelOne.Click
Dim NewNodes As String
NewNodes = TextBox1.Text
TreeView1.Nodes.Add(NewNodes)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLevelTwo.Click
'Create a Level Two Node
Dim ChildNode As String
ChildNode = TextBox2.Text
Dim objNode As TreeNode
objNode = TreeView1.SelectedNode()
TreeView1.Nodes.Remove(TreeView1.SelectedNode)
TreeView1.Nodes.Add(objNode)
objNode.Nodes.Add(ChildNode)
End Sub
Private Sub btnLevelThree_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLevelThree.Click
'Create a Level Three Node
Dim GrandchildNode As String
GrandchildNode = TextBox3.Text
Dim objNode As TreeNode
objNode = TreeView1.SelectedNode()
Dim objNode2 As TreeNode
objNode2 = TreeView1.SelectedNode()
TreeView1.Nodes.Remove(TreeView1.SelectedNode)
TreeView1.Nodes.Add(objNode2)
objNode.Nodes.Add(GrandchildNode)
End Sub