|
-
Nov 1st, 2000, 02:48 PM
#1
Thread Starter
Fanatic Member
Hello everyone,
I need to find the total number of root nodes in a treeview. This is not including child nodes.
Treeview1.Nodes.Count gives me all total nodes.
Thank You in Advance.
Chemically Formulated As:
Dr. Nitro
-
Nov 1st, 2000, 02:59 PM
#2
There is only one Root Node (The First one Added), but if you mean all the Top Level Nodes (Those that have no Parent) then Enumerate the Nodes collection comparing the Node Text to the FullPath property, if the Node is at the TopLevel both properties would be the same, i.e.
Code:
Private Sub Command1_Click()
Dim oNode As Node
For Each oNode In TreeView1.Nodes
If oNode = oNode.FullPath Then List1.AddItem oNode.Text
Next
End Sub
-
Nov 1st, 2000, 03:11 PM
#3
Thread Starter
Fanatic Member
Thanks again Aaron. That did the trick. What if I want to count child nodes?
Chemically Formulated As:
Dr. Nitro
-
Nov 1st, 2000, 03:15 PM
#4
transcendental analytic
This one shouldn't waste too much time on checking all child nodes
Code:
Private Sub Form_Click()
With TreeView1.nodes
Set temp = .Add(, , , "A")
.Add temp, tvwChild, , "AB"
.Add , , , "B"
End With
For Each n In RootNodes(TreeView1.nodes)
Debug.Print n.Text
Next n
End Sub
Function RootNodes(nodes As nodes) As Node()
Dim temp As Node, roots() As Node, n As Long
If nodes.Count Then
ReDim roots(0)
Set temp = nodes.Item(1).Root
Set roots(0) = temp
Set temp = temp.Next
Do Until temp Is Nothing
n = n + 1
ReDim Preserve roots(n)
Set roots(n) = temp
Set temp = temp.Next
Loop
End If
RootNodes = roots
End Function
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 1st, 2000, 03:21 PM
#5
transcendental analytic
BTW, that adds them into an array, not count them, althogh easy to fix, to get the amount of direct childs under a node theres children property
Code:
msgbox node.children
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 1st, 2000, 03:53 PM
#6
Thread Starter
Fanatic Member
Thank You Kedaman.
The Children property combined with Aaron's code will return what I want.
Thank You to both!
Have a good day!!!

Chemically Formulated As:
Dr. Nitro
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|