Solved

Posted on 2003-02-28
Medium Priority
572 Views
I'm trying to click on a node of a treeview and get a count of all nodes below it and throughout any sub levels of the hierachy.

I'm finding this difficult because of the way in which child nodes are 'modelled' with the TreeView component. Why each child is not an item of a children 'collection' escapes me!
0
Question by:DavidRothan
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 200 total points
ID: 8041585

Public Function ChildCount( byval n as Node ) as Long
dim c as Node
dim lngResult as Long

set c = n.Child
while not (c is nothing)
lngResult = lngResult + 1 + ChildCount (c)
set c = c.Next
wend

ChildCount = lngResult
End Function

CHeers
0

LVL 1

Expert Comment

ID: 8041775
Hi,

Here I Give the Code To Finout the Childs For Selected Item

Dim i, j
Dim tempnod, Nod As Node

MsgBox TreeView1.SelectedItem.Children

j = TreeView1.SelectedItem.Children  ' Set the First Child To Traverse
Set Nod = TreeView1.SelectedItem     ' Set the Source Node To Find Childrens

If Nod.Children > 1 Then     ' To Check Child is Avail
MsgBox Nod.Child
TreeView1.Nodes(Nod.Child.Next.Index).Selected = True  ' Set The Next Child as Selected Node
End If

For i = 1 To j - 1    ' Loop Continue Untill The Last Child Reached
MsgBox TreeView1.SelectedItem
Set tempnod = TreeView1.SelectedItem ' Set the Selected as TempNode
If i < j - 1 Then
TreeView1.Nodes(tempnod.Next.Index).Selected = True ' Set The Next Child as Selected Node
End If
Next i

TreeView1.Nodes(Nod.Index).Selected = True ' Set the Source Node as Selected Node
If TreeView1.SelectedItem.EnsureVisible = False Then
TreeView1.SelectedItem.Expanded = True
End If

Put this Code Under The Fllowing For loop

Dim i As Node
For Each i In TreeView1.Nodes
Next

I Hope this Code Help To Findout The Children.

Regards,
Nambi

0

Author Comment

ID: 8041937
I have to award the points to angellll for such a rapid and concise solution to the question. The maddening thing is that angellls code was along the same lines as what I was trying to achieve except I had a loop:

set childnode = thenode.child
do until childnode=thenode.lastsibling

0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
###### Suggested Courses
Course of the Month12 days, left to enroll