Results 1 to 9 of 9

Thread: [RESOLVED] Vb6, Treeview, checkboxes, returning node caption

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Location
    Netherlands
    Posts
    97

    Resolved [RESOLVED] Vb6, Treeview, checkboxes, returning node caption

    Hi,

    I'm working with a TreeView with checkboxes. I would like to make something like this:

    The user checks like 4 out of 10 nodes, and presses a button. the program then loops through the treeview, outputting the caption of every checked node, 1 at a time (with a timer).

    how do i set this up?
    Last edited by JWJWJW; Jun 16th, 2010 at 01:31 AM. Reason: Title
    My Programming Software: Visual Basic 2010
    My Database Program: Office Access 2010

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Vb6, Treeview, checkboxes, returning node caption

    In this example i load a TV with data and then, when pressing a commandbutton only the nodes checked are shown in messageboxes. What's the reason to use a Timer? your idea is waiting a certain amount of time between messageboxes?
    Code:
    Private Sub Form_Load()
        With TreeView1
            .CheckBoxes = True
            .Nodes.Add , , "Root", "Root"
            .Nodes.Add "Root", tvwChild, "Child1", "Child1"
            .Nodes.Add "Root", tvwChild, "Child2", "Child2"
            .Nodes.Add "Root", tvwChild, "Child3", "Child3"
            .Nodes.Add "Root", tvwChild, "Child4", "Child4"
            .Nodes.Item("Root").Expanded = True
        End With
    End Sub
    
    Private Sub Command1_Click()
    Dim lNode As Node
        For Each lNode In TreeView1.Nodes
            If lNode.Checked Then
                MsgBox lNode.Text
            End If
        Next
        Set lNode = Nothing
    End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Location
    Netherlands
    Posts
    97

    Re: Vb6, Treeview, checkboxes, returning node caption

    Hi,

    No, i want to search a database for that value. since there are no database questions allowed here, i thought timer would have a similar type of code.

    Thanks for that code though! i just have 1 more question:
    this is what my treeview looks like:

    GroupA - product1
    - product2
    GroupB - product1
    - product2
    - product3
    GroupC - product1
    GroupD .etc

    When the node of "GroupA" is checked, all child nodes are checked. how can i output (for instance, the way you proposed) only the products, and not the group names?

    Thanks!
    My Programming Software: Visual Basic 2010
    My Database Program: Office Access 2010

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Vb6, Treeview, checkboxes, returning node caption

    GroupA, GroupB, GroupC..etc, all that nodes are Roots? If so, a possible way to avoid showing them is:
    Code:
    Private Sub Command1_Click()
    Dim lNode As Node
        For Each lNode In TreeView1.Nodes
            If Not (lNode Is lNode.Root) And lNode.Checked Then
                MsgBox lNode.Text
            End If
        Next
        Set lNode = Nothing
    End Sub
    If Not (lNode Is lNode.Root) Means: If the Root of this node is not this same node.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Location
    Netherlands
    Posts
    97

    Re: Vb6, Treeview, checkboxes, returning node caption

    Yes, the group nodes are at the root. all of these groups only have children (so there are no childrens children... no grandchildren).

    Your code of comparing the lnode to lnode.root doesn't work somehow. It still shows GroupC when it's clicked.
    My Programming Software: Visual Basic 2010
    My Database Program: Office Access 2010

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Vb6, Treeview, checkboxes, returning node caption

    Oops.. my mistake. Your TreeView only has Group Nodes with Product Nodes (Children)? that's all? or Product children could also have more children? If it is just Group nodes with product children it could be done like this:
    Code:
    Private Sub Command1_Click()
    Dim lNode As Node
        For Each lNode In TreeView1.Nodes
            If lNode.Children = 0 And lNode.Checked Then
                MsgBox lNode.Text
            End If
        Next
        Set lNode = Nothing
    End Sub
    Last edited by jcis; Jun 16th, 2010 at 02:38 AM.

  7. #7
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Vb6, Treeview, checkboxes, returning node caption

    Just added 1 more condition in my previous post to make it also work if there are groups without products..

    Edited: Nevermind, the code should be changed drastically to make it work when having groups without products, but you said this can never happen so i'll leave it like it is now.
    Last edited by jcis; Jun 16th, 2010 at 02:39 AM.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Location
    Netherlands
    Posts
    97

    Re: Vb6, Treeview, checkboxes, returning node caption

    Very nice! It works.

    Thanks alot! need to finish this program tomorrow evening, so this saved a lot of time!
    My Programming Software: Visual Basic 2010
    My Database Program: Office Access 2010

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Location
    Netherlands
    Posts
    97

    Re: Vb6, Treeview, checkboxes, returning node caption

    Yes, i excluded that state when creating the database.
    There can never be groups without products, since a group can only be created when a product is created.

    Thanks though!
    My Programming Software: Visual Basic 2010
    My Database Program: Office Access 2010

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