Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Treeview control (xp)

    does anyone have any experience of using this control?

    I am trying to build an interface that illustrates a telephone exchange (dial 1 for accounts, dial 2 for personnel, then sub menus dial 1 for the accounts manager, dial 2 for the purchase order team ....) but cannot get my head around the logic to control the nodes beyond the second level (ie top level nodes and their children). I have a simple table layout of four columns - ID, Description, Notes, ParentID.

    how can i check to see if a child has a child?

    in the data below i want to illustrate that the technicians are subordinate to the engineers who are subordinate to the ICT group
    purchasing and admin are subordinate to Accounts but i can represent that already.
    ID Description Notes parentid
    1 Accounts abcd -
    2 HR abcd -
    3 Marketing abcd -
    4 Sales abcd 3
    5 ICT abcd -
    6 Engineers abcd 5
    7 Software abcd 5
    8 Admin abcd 1
    9 Purchasing abcd 1
    10 Technicians abcd 6

    i am using this code and can see why i only get two levels. what o dont understand is where and how to test if there is a third/forth/fifth layer to go to?
    Sub List()
    Dim objDB As Database
    Dim objRS As Recordset ' holds node information
    Dim objRS2 As Recordset ' holds child information
    Dim strSQL As String
    Dim strChildSQL As String
    Dim objTVW As Node
    Dim intParentID As Integer

    strSQL = "select * from AD"
    strsql2 = "Select * from AD where ParentID = "

    Set objDB = CurrentDb
    Set objRS = objDB.OpenRecordset(strSQL)

    Form_frmTVW.TreeView0.LineStyle = tvwRootLines
    objRS.MoveFirst

    While Not objRS.EOF
    Set objTVW = Form_frmTVW.TreeView0.Nodes.Add(, , , objRS.Fields("ID"))
    intParentID = objRS.Fields("ID")
    Set objRS2 = objDB.OpenRecordset(strsql2 & intParentID)
    While Not objRS2.EOF
    Form_frmTVW.TreeView0.Nodes.Add objTVW, 4, , objRS2.Fields("ID")
    objRS2.MoveNext
    Wend
    objRS2.Close
    objRS.MoveNext
    Wend

    Set objTVW = Nothing
    Set objRS = Nothing
    Set objDB = Nothing

    End Sub

    hope someone can help (or even follow my poor explanation!)

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Treeview control (xp)

    Sorry to be so late in responding - we've been traveling for the last two weeks. A vacation and that sort of thing.

    As you've discovered, treeview controls are not for the faint of heart! That said, they can be a pretty powerful tool in the right circumstances. I presume you are using the Microsoft version of the control - if not let us know.

    There are a couple of Microsoft KB articles that should be a value. Check out <!mskb=209891>Microsoft Knowledge Base Article 209891<!/mskb> and <!mskb=209927>Microsoft Knowledge Base Article 209927<!/mskb> - they both have info on how to populate multiple level nodes, and you might also find <!mskb=207849>Microsoft Knowledge Base Article 207849<!/mskb> helpful in understanding how Nodes are added - see the References section for some Help pointers. I also believe that a sample databbase with example code came on the developer edition of Access 2000 and 97. Unfortunately I am not on a PC that has either of those installed.
    Wendell

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Treeview control (xp)

    I don't know if you still need this. You can use a recursive procedure to add unlimited levels. See the attached text file. The first procedure adds the first level (records with empty ParentID); for each node it calls the second procedure. The second procedure adds the children of the parent node passed to it, and calls itself for each child node.
    Attached Files Attached Files

Posting Permissions

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