Results 1 to 12 of 12
  1. #1
    New Lounger
    Join Date
    Jul 2002
    Location
    Australia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Collapse a treeview control (Access 2000)

    I am using a TreeView control (Microsoft Treeview Control 6.0 (SP4) - Class MSComctlLib.TreeCtrl.2) to display a large quantity of heirachical data to seven levels of indenture. By default, the treeview opens with all nodes expanded. Can anyone help me with a method to programatically collapse all nodes?

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Collapse a treeview control (Access 2000)

    Use:

    tvwName.Object.Nodes("KeyOfRootNode").Expanded = False

    That is assuming you have one and only one parent Node. Like the following:

    <pre>Root
    +--Child
    +--Child2
    +--Child3
    +--Child4
    +--Child5</pre>

    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    New Lounger
    Join Date
    Jul 2002
    Location
    Australia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Collapse a treeview control (Access 2000)

    Bryan
    Thanks for your assistance. Unfortunately, it hasn't solved my problem - it may have to do with the way that I populate my treeview control.
    Each of the seven node levels use the same key field ("LCN") based on a different source query. The format of the LCN field alternates between letters and numbers to indicate the depth of indenture so the treeview structure looks like this:
    AA
    AA01
    AA01AA
    AA01AA01
    AA01AA01AA
    AA01AB
    AA02
    AA03
    AA03AA ......etc
    I populate the trrview using the follwing code:
    PopulateTree trvwTest, "qry_level1", 1, "Display", "LCN"
    PopulateTree trvwTest, "qry_level2", 2, "Display", "LCN", "Parent"
    PopulateTree trvwTest, "qry_level3", 3, "Display", "LCN", "Parent"
    PopulateTree trvwTest, "qry_level4", 4, "Display", "LCN", "Parent"
    PopulateTree trvwTest, "qry_level5", 5, "Display", "LCN", "Parent"
    PopulateTree trvwTest, "qry_level6", 6, "Display", "LCN", "Parent"
    PopulateTree trvwTest, "qry_level7", 7, "Display", "LCN", "Parent"
    qry_level1 only includes records with a 2 character LCN, qry_level2 a 4 character LCN, qry_level3 a 6 character LCN etc.
    When I run the code 'trvwTest.Object.Nodes("LCN").Expanded = False' (linked to a command button) I get a VB runtime error (35601 - Element not found).
    Any Thoughts

    Mick

  4. #4
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Collapse a treeview control (Access 2000)

    Mick,

    Sorry for the delayed response.

    The reason you are getting the 3501 error is because you are using LCN as the key of the Node you want collapsed.

    You need to use the 2 digit key, AA, BB, CC,...

    trvwTest.Object.Nodes("BB").Expanded = False ' Where BB is the Key of the node.

    But on thing that just occured to me is, why do you need to collapse the Tree? The Treeview should open and fill collapsed, unless you have some code to expand it.

    If that doesn't work, post your PopulateTree Code so I can have a look at it and see how you are populating the TreeView
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  5. #5
    New Lounger
    Join Date
    Jul 2002
    Location
    Australia
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Collapse a treeview control (Access 2000)

    Bryan
    I have been persevering with the problem and can now programmatically control the level of nodes (one to seven) displayed, add new nodes and delete a node and its siblings. Problem solved - thanks again for your help.

    Mick

  6. #6
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Collapse a treeview control (Access 2000)

    It would be helpful to see your working code.

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

    Re: Collapse a treeview control (Access 2000)

    The original poster mfo hasn't logged in for almost 5 years, so don't hold your breath.

  8. #8
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Collapse a treeview control (Access 2000)

    I was addressing all people here (you have to read between the lines LOL) if they have any clues on this.

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

    Re: Collapse a treeview control (Access 2000)

    Since you wrote "... to see your working code" (Italics mine), you appeared to be addressing mfo, not all people here.

    As Bryan Carbonell pointed out, a TreeView control starts out collapsed by default. You have to write code to make it start with one or more nodes expanded, e.g.

    MyTreeview.Nodes("MyRoot").Expanded = True

    where MyTreeView is the name of a treeview control and MyRoot is the key value of the root node.

  10. #10
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Collapse a treeview control (Access 2000)

    Is there any doco i could learn how to use the treeview control?

    I did address mfo, but thought others may have responded to me.

    Thank you for responding.

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

    Re: Collapse a treeview control (Access 2000)

    The official reference material: TreeView Control.

    See How to fill a Treeview control recursively in Access 2000 for an example of how to populate a treeview control.
    A more complicated example is found in How to use TreeView control Drag-and-Drop capabilities in Access 2000.

    I have attached a sample database that uses data from the Northwind database.
    Attached Files Attached Files

  12. #12
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Collapse a treeview control (Access 2000)

    Thanks Hans that should provide a great start for me to learn about this function.

Posting Permissions

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