CSDN博客

img lang_csdn

TreeView中如何选中一个父节点同时选中所有的子节点和孙节点。。。

发表于2004/10/11 18:12:00  1467人阅读

分类: VB6.0

----------------------------------------------------------------------------
'
'Author:lihonggen0
'Date:2003-1-20
'功能:选择Treeview节点下所有节点
'----------------------------------------------------------------------------

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
    Next
End 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)        '对子节点
        End If
        If bNext Then
            Call CheckChild(Node.Next, bCheck, True, bChild)          '对同一层节点
        End If
     End If
End Sub

Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
    Call CheckChild(Node, Node.Checked, False, True)                    '处理子节点
End Sub

阅读全文
0 0

相关文章推荐

img
取 消
img