Results 1 to 6 of 6

Thread: Tree help

  1. #1

    Thread Starter
    Addicted Member hyousuf2's Avatar
    Join Date
    Dec 2004
    Location
    Dublin
    Posts
    226

    Tree help

    i have made a tree with checkboxes, i want to write a code that on its click event the node itself get selected/deselected and if it is a parent node then all of its child should also get selected/deselected. the tree has only two levels. this is the initial code which i write

    VB Code:
    1. Dim nd As Node
    2.     Set nd = Tree.Nodes.Add()
    3.     nd.Key = "AB"
    4.     nd.Text = "Address Book"
    5.     nd.Tag = "HEADS"
    6.        
    7.    
    8.     Set nd = Tree.Nodes.Add()
    9.     nd.Key = "QR"
    10.     nd.Text = "Query List"
    11.     nd.Tag = "HEADS"

  2. #2
    Addicted Member Luke K's Avatar
    Join Date
    Jun 2004
    Location
    Perth, Australia
    Posts
    183

    Re: Tree help

    VB Code:
    1. Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
    2.  
    3.     On Error GoTo errh:
    4.     Dim nodex As Object
    5.  
    6.     If Node.Children = 0 Then
    7.         Call MsgBox("This node has no children!", vbInformation + vbOKOnly, "!")
    8.         Exit Sub
    9.     Else
    10.         Set nodex = Node.Child
    11.         TreeView1.Nodes(nodex.Index).Checked = True
    12.         While (Not IsNull(nodex))
    13.             Set nodex = nodex.Next
    14.             TreeView1.Nodes(nodex.Index).Checked = True
    15.         Wend
    16.     End If
    17. errh:
    18.     Call MsgBox("All children of " & Node.Text & "(" & Node.Index & ") Checked")
    19.  
    20. End Sub
    Artificial Intelligence At War! - The best game of its genre
    Program your own robot and watch it fight in 3d!
    Droidarena 3

    If I have been useful, please Rate My Post

    Support FireFox -
    Microsoft Visual Studio .NET Professional 2003
    Microsoft Visual Studio 6, Enterprise Edition
    Microsoft Windows XP Professional, Service Pack 2

  3. #3
    Lively Member smartrajesh's Avatar
    Join Date
    Feb 2005
    Posts
    94

    Re: Tree help

    first of all you have to find the no of childrens for a particular parent node.

    like... "tree1.children" now u can get the no of children and u should check the condition every click of tree control whether the value is equal to the no of children. using variable..(increment the variable i+1 for every click ok)....r u got it....

  4. #4

    Thread Starter
    Addicted Member hyousuf2's Avatar
    Join Date
    Dec 2004
    Location
    Dublin
    Posts
    226

    Re: Tree help

    the supplied code is not working, if it is a parent node n i check it, it just displays the msg n its children does not get checked

  5. #5

    Thread Starter
    Addicted Member hyousuf2's Avatar
    Join Date
    Dec 2004
    Location
    Dublin
    Posts
    226

    Re: Tree help

    hi
    i managed to rectify the mistake maself but thnkx neways
    check out ma next thread

  6. #6
    Addicted Member Luke K's Avatar
    Join Date
    Jun 2004
    Location
    Perth, Australia
    Posts
    183

    Re: Tree help

    Well, Yes, that code does work
    You just arent adding any child nodes from the look of the first post of this thread.
    Artificial Intelligence At War! - The best game of its genre
    Program your own robot and watch it fight in 3d!
    Droidarena 3

    If I have been useful, please Rate My Post

    Support FireFox -
    Microsoft Visual Studio .NET Professional 2003
    Microsoft Visual Studio 6, Enterprise Edition
    Microsoft Windows XP Professional, Service Pack 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width