Click to See Complete Forum and Search --> : count number of nodes


aamir55
December 20th, 2008, 12:27 AM
i want to count to number of nodes under each root node so i m doing so

Dim n As Integer
For Each RootNode As TreeNode In treeAlbum.Nodes
n = RootNode.Nodes.Count
Next
MessageBox.Show("nodes " & n)

it is counting number of nodes but not exact,some time it is showing more nodes and some time it is showing less time.
plz help me
------------------------------------------------

dglienna
December 20th, 2008, 12:52 AM
Show more code. Is that a click event?

aamir55
December 21st, 2008, 12:02 AM
it is not click event
it is after select event of tree view

TheCPUWizard
December 21st, 2008, 12:06 AM
You are ASSIGNING the value...NOT accumulating it!

What is being returned is the number of nodes in the last item scanned.

You need a recursive (yes I know it can be flattened!) way to count the nodes...