• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

using treeview

Hello Guys,
                 I want to use a treeview to display a set of processes. Each process has multiple subprocesses. I want to be able to check either whole process(es)  or individual subprocesses on a treeview. Could you help and write a programm that ,say , displays processes a,b,c with each having subs respectively a1,a2,a3 ....b1,b2,b3 ......so on,   When the choice is made and the needed nodes and subnodes are checked on the treeview a button triggers a msg box displaying the options that have been checked.

Thank you!
0
Autofreak
Asked:
Autofreak
  • 3
  • 3
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Create a new project and add a treeview and a commandbutton.  Set the checkboxes property of the treeview to true:

Option Explicit

Private Sub Form_Load()
    Dim nodX As Node
   
    Set nodX = TreeView1.Nodes.Add(, , "A", "A")
    Set nodX = TreeView1.Nodes.Add("A", tvwChild, "A1", "1")
    Set nodX = TreeView1.Nodes.Add("A1", tvwChild, "A1a", "a")
    Set nodX = TreeView1.Nodes.Add("A1", tvwChild, "A1b", "b")
    Set nodX = TreeView1.Nodes.Add("A1", tvwChild, "A1c", "c")
    Set nodX = TreeView1.Nodes.Add("A", tvwChild, "A2", "2")
    Set nodX = TreeView1.Nodes.Add("A2", tvwChild, "A2a", "a")
    Set nodX = TreeView1.Nodes.Add("A2", tvwChild, "A2b", "b")
    Set nodX = TreeView1.Nodes.Add("A2", tvwChild, "A2c", "c")
    Set nodX = TreeView1.Nodes.Add("A", tvwChild, "A3", "3")
    Set nodX = TreeView1.Nodes.Add("A3", tvwChild, "A3a", "a")
    Set nodX = TreeView1.Nodes.Add("A3", tvwChild, "A3b", "b")
    Set nodX = TreeView1.Nodes.Add("A3", tvwChild, "A3c", "c")
   
    Set nodX = TreeView1.Nodes.Add(, , "B", "B")
    Set nodX = TreeView1.Nodes.Add("B", tvwChild, "B4", "4")
    Set nodX = TreeView1.Nodes.Add("B4", tvwChild, "B4a", "a")
    Set nodX = TreeView1.Nodes.Add("B4", tvwChild, "B4b", "b")
    Set nodX = TreeView1.Nodes.Add("B4", tvwChild, "B4c", "c")
    Set nodX = TreeView1.Nodes.Add("B", tvwChild, "B5", "5")
    Set nodX = TreeView1.Nodes.Add("B5", tvwChild, "B5a", "a")
    Set nodX = TreeView1.Nodes.Add("B5", tvwChild, "B5b", "b")
    Set nodX = TreeView1.Nodes.Add("B5", tvwChild, "B5c", "c")
    Set nodX = TreeView1.Nodes.Add("B", tvwChild, "B6", "6")
    Set nodX = TreeView1.Nodes.Add("B6", tvwChild, "B6a", "a")
    Set nodX = TreeView1.Nodes.Add("B6", tvwChild, "B6b", "b")
    Set nodX = TreeView1.Nodes.Add("B6", tvwChild, "B6c", "c")
   
    Set nodX = TreeView1.Nodes.Add(, , "C", "C")
    Set nodX = TreeView1.Nodes.Add("C", tvwChild, "C7", "7")
    Set nodX = TreeView1.Nodes.Add("C7", tvwChild, "C7a", "a")
    Set nodX = TreeView1.Nodes.Add("C7", tvwChild, "C7b", "b")
    Set nodX = TreeView1.Nodes.Add("C7", tvwChild, "C7c", "c")
    Set nodX = TreeView1.Nodes.Add("C", tvwChild, "C8", "8")
    Set nodX = TreeView1.Nodes.Add("C8", tvwChild, "C8a", "a")
    Set nodX = TreeView1.Nodes.Add("C8", tvwChild, "C8b", "b")
    Set nodX = TreeView1.Nodes.Add("C8", tvwChild, "C8c", "c")
    Set nodX = TreeView1.Nodes.Add("C", tvwChild, "C9", "9")
    Set nodX = TreeView1.Nodes.Add("C9", tvwChild, "C9a", "a")
    Set nodX = TreeView1.Nodes.Add("C9", tvwChild, "C9b", "b")
    Set nodX = TreeView1.Nodes.Add("C9", tvwChild, "C9c", "c")
   
    Set nodX = TreeView1.Nodes.Add(, , "D", "D")
    Set nodX = TreeView1.Nodes.Add("D", tvwChild, "D10", "10")
    Set nodX = TreeView1.Nodes.Add("D10", tvwChild, "D10a", "a")
    Set nodX = TreeView1.Nodes.Add("D10", tvwChild, "D10b", "b")
    Set nodX = TreeView1.Nodes.Add("D10", tvwChild, "D10c", "c")
    Set nodX = TreeView1.Nodes.Add("D", tvwChild, "D11", "11")
    Set nodX = TreeView1.Nodes.Add("D11", tvwChild, "D11a", "a")
    Set nodX = TreeView1.Nodes.Add("D11", tvwChild, "D11b", "b")
    Set nodX = TreeView1.Nodes.Add("D11", tvwChild, "D11c", "c")
    Set nodX = TreeView1.Nodes.Add("D", tvwChild, "D12", "12")
    Set nodX = TreeView1.Nodes.Add("D12", tvwChild, "D12a", "a")
    Set nodX = TreeView1.Nodes.Add("D12", tvwChild, "D12b", "b")
    Set nodX = TreeView1.Nodes.Add("D12", tvwChild, "D12c", "c")
   
    Command1.Caption = "List Checked Items"
End Sub

Private Sub Command1_Click()
    Dim n As MSComctlLib.Node
   
    For Each n In TreeView1.Nodes
        If n.Checked Then
            MsgBox "Key = " & n.Key & " : Text = " & n.Text
            ' or do something with n here
        End If
    Next n
End Sub
0
 
AutofreakAuthor Commented:
I got an error :
                       on this line   Set nodX = TreeView1.Nodes.Add(, , "A", "A")


 run-time error 35602
Key is not unique in collection
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Ok...

Did you add a TreeView?  Is it empty?...

Start with a new project and add a treeview and a commandbutton.  Set the checkboxes property of the treeview to true and paste the code I gave above.  It's works without error on my system.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
AutofreakAuthor Commented:
Hey Idle_Mind,
                         that's strange, I moved the code to VBA in Excel and it worked, Biu how do I make it work in VB6? What may be the matter?

Thanks
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Not sure what's going on there.  It's working for me in VB6.

Describe to me how you are creating your project, then adding the controls and code.
0
 
AutofreakAuthor Commented:
I tried once again with VB6 and it worked perfectly. Thanks a lot, I must have done somth wrong, you know how it is with computers ;)

By the way, I am posting a continuation to this Q, your participation would be greatly appreciated.

Serge
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now