Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

VB6 Treeview with checkbox

muswellmuswell Posts: 1Member
I have a question about using checkboxes with vb6 treeviews.

I want to cascade down the value of the checkbox to its children.

Thus if the parent is ticked all the children automatically become ticked.

What is the easiest way to do this ?

I cant find any methods that would help - the children function tells me how many children the parent has but I cant see any way of referencing an indovidual child (or all of them in sequence)

Any help would be appreciated.

Comments

  • GenjuroGenjuro Posts: 913Member
    : I have a question about using checkboxes with vb6 treeviews.
    :
    : I want to cascade down the value of the checkbox to its children.
    :
    : Thus if the parent is ticked all the children automatically become ticked.
    :
    : What is the easiest way to do this ?
    :
    : I cant find any methods that would help - the children function tells me how many children the parent has but I cant see any way of referencing an indovidual child (or all of them in sequence)
    :
    : Any help would be appreciated.

    If I'm not forgetting something on the way, Node objects have a Child property, which returns the first child of the node, and a "next property", which returns the following node in the tree, at a given hierarchy level; this means that a tree is structured this way:

    [code]
    Node1
    Node1.Child
    Node1.Child.Next
    Node1.Child.Next.Next
    Node1.Child.Next.Next.Next
    Node2
    Node2.Child
    Node2.Child.Child
    Node2.Child.Child.Next
    Node2.Child.Child.Next.Next
    Node2.Child.Next
    Node2.Child.Next.Next
    [/code]
    and so on.

    Given that you can directly reference a node using a node object, it's not hard to iterate over nodes, and, if you haven't *that* many levels in your tree, recursion is easy, too:

    [code]
    sub RecurseWalkNode(CurNode as Node, Optional TabCount as Integer = 0)
    Dim TempNode as Node
    Dim NextNode as Node

    'replace this line as needed
    Debug.print string$(TabCount, vbTab) & CurNode.Text

    Set NextNode = CurNode.Child
    do while(Not (NextNode is Nothing))
    Call RecurseWalkNode(NextNode, TabCount + 1)
    Set TempNode = NextNode.Next
    Set NextNode = TempNode
    Loop
    End sub
    [/code]

    You call this function and pass it a node; the function should iterate over the tree and print the whole hierarchy spawning from that node, writing it to the debug window. You can replace the Debug.print with whatever you need and it'll be fine, or send down different parameters through the stack, as long as you leave the first parameter untouched.
Sign In or Register to comment.