Results 1 to 13 of 13

Thread: TreeView (A2k)

  1. #1
    Star Lounger
    Join Date
    Jan 2002
    Location
    Washington State
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    TreeView (A2k)

    I have a treeview control using checkboxes.

    There are three levels in this particular treeview.

    If the user checks a node in the third level then I need the parent node in the second and first levels to also be checked at the same time. I can't figure out how to do this but I'm sure it can be done.

    Thanks!
    Sam

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

    Re: TreeView (A2k)

    Try this:
    <code>
    Private Sub TreeView0_NodeCheck(ByVal Node As Object)
    Dim intLevel As Integer
    Dim nodPar As Node
    ' Get out if node was unchecked
    If Node.Checked = False Then
    Exit Sub
    End If
    Set nodPar = Node
    ' Part 1: compute level of node that has been checked
    intLevel = 0
    Do While Not nodPar Is Nothing
    intLevel = intLevel + 1
    Set nodPar = nodPar.Parent
    Loop
    ' Did the user check a level 3 node?
    If intLevel = 3 Then
    ' Part 2: check the nodes up the chain
    Set nodPar = Node
    Do While intLevel > 1
    intLevel = intLevel - 1
    Set nodPar = nodPar.Parent
    nodPar.Checked = True
    Loop
    End If
    End Sub</code>

  3. #3
    Star Lounger
    Join Date
    Jan 2002
    Location
    Washington State
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TreeView (A2k)

    Hans,

    It's perfect! I was then able to modify the code to handle the process of unchecking child nodes when a parent node gets unchecked.

    I sure appreciate your help!
    Have a great weekend!
    Sam

  4. #4
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington, Cheshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TreeView (A2k)

    What is a treeview control, please? I typed 'treeview' into Access help and zilch was the output.
    Please can you enlighten me?
    Thanks
    Silverback
    Silverback

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

    Re: TreeView (A2k)

    1. General: a TreeView is what you see (for example) in the left hand pane of Windows Explorer. A TreeView is used to visualize a hierarchical structure such as that of drives and folders. You can expand and contract nodes in the 'tree'.

    2. The TreeView control is not part of Microsoft Access itself. It is a separate ActiveX control. To use it in Access:
    - Create a form in design view.
    - Click the 'More Controls' button on the Control Toolbox.
    - You'll see a (very) long list of ActiveX controls.
    - Hover the mouse pointer over the downwards pointing triangle at the bottom of the list.
    - Scroll down until you see 'Microsoft TreeView Control, version 6.0'. (There's also a version 5.0 but you don't want that one.)
    - Click on this item, then either drag a rectangle on the form or click on the form.
    - To set specific properties of the TreeView control, right-click it, then select TreeCtrl Object | Properties.

    Unfortunately, Access doesn't display help about the TreeView control, and IntelliSense is incomplete.
    The reference material on TreeView can be found on MSDN: TreeView Control.
    But if you want to learn how to use it, it's best to study examples. See for example <post:=717,626>post 717,626</post:> (links and attached example).

  6. #6
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington, Cheshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TreeView (A2k)

    Thanks for the pointers.
    I haven't got a use for TreeView yet, but it's nice to know it's available.
    Regards
    Silverback
    Silverback

  7. #7
    Star Lounger
    Join Date
    Jan 2002
    Location
    Washington State
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TreeView (A2k)

    Enough pulling my hair out. It's time to humble myself and ask for help...

    I've recently been enjoying the challenge of learning how to use the treeview control effectively. I really appreciate the help Hans provided as it was a springboard, of sorts, for me to finally dive into learning about this very useful control. I've been meaning to learn it for years!

    So armed with this newly acquired knowledge I created a form using a treeview control. I then used this form as a subform (placed on a tab control on the parent form). The problem, apparently, is that once the TreeView receives focus any controls on the parent form no longer react to keyboard activity. Basically the TreeView retains a sort-of dual focus with whatever control is being selected on the parent form. And only the TreeView will respond to the keyboard. It's both crazy and strange that the TreeView won't relinquish its focus once a new control is selected. For what it's worth, Microsoft documents the problem here: http:// http://support.microsoft.com/kb/210608/en-us

    Microsoft recommends three things:
    1. Don't use a subform. Place the treeview directly on the tab. (Which is exactly what I did. Too bad I didn't read this article first!)
    2. If you must use a subform, click on a non-Active X control in the subform to remove the focus from the TreeView before changing the focus to a control on the parent form.
    3. Close and reopen the form. Then go to the control you want to work with on the parent form.

    In my mind, the only option worth considering is #1. So I went that route. And sure enough it works. And I'd be happy to leave it at that. But two additional problems came up. (Typical, huh?) And it's these issues that brings me here asking for advice or suggestions:

    1. My TreeView uses checkboxes. So naturally I have a command button to "Select All" nodes. Originally (going the subform route) my nodes would all select without any noticeable lag. I didn't change any code, but now with the TreeView placed directly on the tab control the same process runs significantly slower. I can actually watch each individual node become checked as the code runs. Obviously that's not acceptable. Why would there be a difference in speed?

    2. The TreeView control spills out of the tab control (to the very top-left corner of the form) when the form opens and the tree view is populated. It's very similar to <post#=247208>post 247208</post#>. I didn't have the problem using the subform. Why now?

    I'd prefer to stick with my original plan (the subform) but, as you might imagine, it's essential that my users be able to use their keyboard after working with the TreeView. Is there a work-around that MS hasn't documented?

    Thanks for listening. Sorry this is such a long post.
    Sam

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

    Re: TreeView (A2k)

    1. I have no idea why checking all boxes is slow.

    2. I'm afraid this is a bug in the way the treeview control interacts with Access, without a real solution.

    Sorry to be so unhelpful!

  9. #9
    Star Lounger
    Join Date
    Jan 2002
    Location
    Washington State
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TreeView (A2k)

    That's okay, Hans. Thanks for the reply though.

    I was afraid I might have to settle with these issues.

    I tried another work-around:
    I did away with the tab control and the subform route. Instead, I created my form using toggle buttons to mimic the feel of a tab control. After a toggle button is selected I would toggle the visible property for certain controls. When finished, it looked just like my form using the tab control - without the two issues in my last post! Cool, huh?

    The new problem I found, after creating the form, is that when the visible property of a TreeView control is set to False all selections are lost! This control sure is quirky!

    The best option I can think of is to save the selections before setting the visible property to False. If the user selects the toggle button to make the TreeView visible again then I iterate through the nodes and check the ones that were previously stored. Can anyone think of a better option to consider?

    Thanks,
    Sam

  10. #10
    Star Lounger
    Join Date
    Jan 2002
    Location
    Washington State
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TreeView (A2k)

    Okay, for anyone who cares...

    I stumbled across a hokey work-around that works and doesn't cause me too much grief.

    I went back to my original idea: the subform TreeView on a tab control in the parent form.

    I added a command button that hides behind the TreeView control named "cmdFinish." (Note that for my work-around to work the visible property of this command button has to be set to True.) There isn't any code attached to this command button. It's just a non ActiveX control that I can use within the subform to set focus to.

    In the On Enter event for any field on the parent form that might require the use of a keyboard I call a subroutine using:
    ClearTreeViewFocus (Screen.ActiveControl.Name)

    Private Sub ClearTreeViewFocus(str As String)
    Me.sfrmTree.Form!cmdFinish.SetFocus
    Me.Controls(str).SetFocus
    End Sub

    Essentially, anytime a field on the parent form receive focus the command button on the subform receives the focus next which assures me that the TreeView control no longer has focus. I then return the focus to the field on the parent form that received focus.

    Hokey? Absolutely. But it works. Finally!

    Still, is there a more efficient way of doing this?

    Take care,
    Sam

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

    Re: TreeView (A2k)

    I'm glad you've found a "workable" workaround...

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

    Re: TreeView (A2k)

    If you get completely frustrated with the Microsoft TreeView, you might want to look at the one from DBI Technologies http://www.dbi-tech.com/ctTree.asp - we've used it for several years on a commercial product and it gives much greater flexibility and better performance. And you can use it with subforms, even nested subforms.
    Wendell

  13. #13
    Star Lounger
    Join Date
    Jan 2002
    Location
    Washington State
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TreeView (A2k)

    Wendell,

    Thanks for the suggestion. I'll keep it in mind.

    Much appreciated,
    Sam

Posting Permissions

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