|
把我的应用例子上传,希望寻求统计treeview某节点及其下属节点数的朋友有所帮助。我在使用中,以下代码可行。如果在使用中遇到不对的地方或有改进之处,请发短信息告知。谢谢!
Public Sub fenzhicount(ByVal Node As Object)
'分支统计
Dim x As Long
Dim a As Long
Dim xbnode As Node
a = Mid(Node.Key, 2, 5) '我的树节点的key都是由N和access表的序号自动生成,如"N12345”
If a = 1 Or a = 0 Then '根节点则绕过历遍进行统计
x = Form_世系图.TreeView0.Nodes.Count - 1 ‘节点的key由N0开始,N0节点是先祖,不是某人故减1
Form_世系图.Text12 = x ’treeview控件放置在世系图窗体,统计数在text12控件显示
Exit Sub
Else
x = 1
If Node.Children = 0 Then Exit Sub ‘如果没有下属节点,则只有他自己
Set xbnode = Node
GoTo xbxh
End If
xbxh:
'如果有子女,进行子女循环统计
Do Until xbnode.Children = 0
Set xbnode = xbnode.Child
x = x + 1
Loop
GoTo xdxh
xdxh:
'如果不是最小,转入弟弟,否则转回上辈
Do Until xbnode.Text = xbnode.LastSibling
Set xbnode = xbnode.Next
x = x + 1
GoTo xbxh
Loop
GoTo fhsb
fhsb:
'如果不是选中的节点,返加上辈
Do Until Mid(xbnode.Key, 2, 5) = a
Set xbnode = xbnode.Parent
If Mid(xbnode.Key, 2, 5) <> a Then GoTo xdxh
Loop
Form_世系图.Text12 = x
End Sub |
|