|
-
Nov 6th, 2002, 02:54 PM
#1
Thread Starter
Lively Member
Counting child nodes in a treeview
I have a treeview that is populated when the my form loads. Now I want to be able to count the child nodes for any parent node that a user selects.
Is their an easy way to do get the # of children ?
Thanks...
-
Nov 6th, 2002, 09:51 PM
#2
Since there is no .Count property, you can do this:
VB Code:
Dim objNode As TreeNode
Dim intCount as Integer
TreeView1.Nodes.Add("A")
TreeView1.Nodes.Add("B")
intCount = 0
For Each objNode In TreeView1.Nodes
intCount += 1
Next
MsgBox(intCount)
Hope it helps,
-
Nov 7th, 2002, 08:34 AM
#3
Thread Starter
Lively Member
Thanks for your reply.....
Yes that will count the nodes but I need to count ONLY the child nodes of the parent that the user selects.
eg.
Customer <--- currently selected parent w/ 3 children
Order
Order
Order
Customer
Customer
Customer
If I can get the count of the currently selected parent's children I want to use that count to display in the status bar the number of orders for that customer. However, my problem is ... how can I tell the level of the node and only count the children of that selected parent ?
Thanks so very much for any help.
-
Nov 7th, 2002, 10:37 AM
#4
I dont have .Net in front of me right now, but the nodes in a treeview are recursive, so every node has a .Nodes property that can be looped through. All you have to do is find the selected node and loop through its .Nodes property.
-
Dec 17th, 2003, 04:12 PM
#5
Frenzied Member
couldn't you check against the index? if it's zero, then it's a parent, right?
if treeview1.nodes...index > 0 then
'count them
something like that?
-
Dec 17th, 2003, 05:12 PM
#6
Frenzied Member
VB Code:
' give the index of the node
' True counts all levels of children
' False only counts one level deep in the children
TreeView1.Nodes(0).GetNodeCount(True)
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
|