D
Don
I thought each Treeview node had a unique index in the nodes
collection but apparently I was wrong.
I'm pretty sure the VB6 Treeview had unique node indexs but I don't
want to set up an old computer with VB6 installed to check it.
Please try the following tree structure and tell me if I'm nuts:
Families
----Jones
--------James
------------Frank
----Smith
--------Willie
------------Bob
------------Lary
==================
1. Put a Treeview and a Listbox on a form.
2. Name the Treeview TV and paste the following code in the
appropriate events
3. Click the tree nodes and observe the index of each.
I understand that each node has its own nodes collection but is there
a unique identifier for every node? If so, how do you get it. Without
a unique index it seems to lead to some whacky results if you do the
following:
tv.Nodes.Remove(tv.SelectedNode)
WHAT AM I MISSING?
Thanks,
Don
Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim nod As TreeNode, wnod As TreeNode
nod = tv.Nodes.Add("Families")
nod = nod.Nodes.Add("Jones")
nod = nod.Nodes.Add("James")
nod = nod.Nodes.Add("Frank")
nod.EnsureVisible()
nod = tv.Nodes(0).Nodes.Add("Smith")
wnod = nod.Nodes.Add("Willie")
nod = wnod.Nodes.Add("Bob")
nod = wnod.Nodes.Add("Larry")
nod.EnsureVisible()
nod = tv.Nodes(0).Nodes.Add("Johnson")
nod.EnsureVisible()
'tv.HideSelection = False
End Sub
Private Sub tv_AfterSelect(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.TreeViewEventArgs) Handles tv.AfterSelect
Dim n As TreeNode = tv.SelectedNode
On Error Resume Next
With ListBox1
.Items.Clear()
.Items.Add("Index: " & n.Index.ToString)
.Items.Add("Text: " & n.Text)
.Items.Add("Kids: " & n.GetNodeCount(True))
.Items.Add("Parent: " & n.Parent.Index)
End With
End Sub
collection but apparently I was wrong.
I'm pretty sure the VB6 Treeview had unique node indexs but I don't
want to set up an old computer with VB6 installed to check it.
Please try the following tree structure and tell me if I'm nuts:
Families
----Jones
--------James
------------Frank
----Smith
--------Willie
------------Bob
------------Lary
==================
1. Put a Treeview and a Listbox on a form.
2. Name the Treeview TV and paste the following code in the
appropriate events
3. Click the tree nodes and observe the index of each.
I understand that each node has its own nodes collection but is there
a unique identifier for every node? If so, how do you get it. Without
a unique index it seems to lead to some whacky results if you do the
following:
tv.Nodes.Remove(tv.SelectedNode)
WHAT AM I MISSING?
Thanks,
Don
Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim nod As TreeNode, wnod As TreeNode
nod = tv.Nodes.Add("Families")
nod = nod.Nodes.Add("Jones")
nod = nod.Nodes.Add("James")
nod = nod.Nodes.Add("Frank")
nod.EnsureVisible()
nod = tv.Nodes(0).Nodes.Add("Smith")
wnod = nod.Nodes.Add("Willie")
nod = wnod.Nodes.Add("Bob")
nod = wnod.Nodes.Add("Larry")
nod.EnsureVisible()
nod = tv.Nodes(0).Nodes.Add("Johnson")
nod.EnsureVisible()
'tv.HideSelection = False
End Sub
Private Sub tv_AfterSelect(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.TreeViewEventArgs) Handles tv.AfterSelect
Dim n As TreeNode = tv.SelectedNode
On Error Resume Next
With ListBox1
.Items.Clear()
.Items.Add("Index: " & n.Index.ToString)
.Items.Add("Text: " & n.Text)
.Items.Add("Kids: " & n.GetNodeCount(True))
.Items.Add("Parent: " & n.Parent.Index)
End With
End Sub