-------------------------------------------------- -------------------------- '' Author: lihonggen0'date: 2003-1-20 'Features: Select all nodes under the TreeView node - -------------------------------------------------- -------------------------
Private Sub Form_Load () TreeView1.checkboxes = true treeview1.nodes.add, "r", "root", "root" TreeView1.nodes.add "root", TVWchild, "Key1", "aa" TreeView1.nodes.Add "Key1", TVWChild, "Key11", "CCC"
TreeView1.nodes.add "root", TVwchild, "key2", "bb" TreeView1.nodes.add "key2", TVwchild, "key21", "ddd" treeview1.nodes.add "key2", TVWchild, "key211" , "eee" For I = 1 To TreeView1.Nodes.Count TreeView1.Nodes (I) .Expanded = True NextEnd Sub Private Sub CheckChild (ByVal Node As MSComctlLib.Node, ByVal bCheck As Boolean, Optional ByVal bNext As Boolean = True, optional ByVal bChild As Boolean = True) If Not node Is Nothing Then Node.Checked = bCheck If Node.Children And bChild Then Call CheckChild (node.Child, bCheck, True, True) 'child node End If If bNext Then Call CheckChild (Node.Next, BCheck, True, BChild "to the same layer node end if End ifend SUB
Private sub treeview1_nodecheck (byval node as mscomctllib.node) call checkchild (node, node.checked, false, true) handle sub-node end SUB