MS Tree View - manipulation

My Fellow experts, I am working with the Tree View control within an MS Access form.

This tree has various root notes (at the moment we have 6 of them) off of these root nodes we have a number of important immediate child nodes.

The Check box nature of the tree view has been enabled.

What I would like to do is disable checkboxes on two parent nodes (I do know which ones), leaving checkboxes enabled on the 4 remaining parent nodes.

Of the 4 nodes which have check boxes enabled, I then want to disable the check boxes on some (not all) of the child nodes (again, I know which ones).

Is this possible, if so, would you be able to help me with the code.

many thanks
LVL 11
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I don't think you can enable only SOME of the checkboxes; it's an all or nothing setup.

You could use the Click or Expand event of a Node to determine if you should show Checkboxes, and then toggle the property based on that, but if you have multiple expanded Nodes, this would not be a visually appealing event.

Or you could use a 3rd party control with more functionality that the MS ones.
RunriggerAuthor Commented:
emmm, not great news but something to work with nonetheless!

As an alternatively, I am display them on all nodes, that's fine, however, where I had originally planned to disable them, I have instead tried to make it so that when they check the box, the code automatically unchecks the box;

Private Sub treeAccounts_NodeCheck(ByVal Node As Object)
    If Left(Node.Key, 4) = "T001" Then Node.Checked = False
End Sub

however, the box always checks anyway (there doesn't not appear to be a way to "cancel" the checking of the box, so this option doesn't work for me either.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I haven't used the MS Treeview in quite some time, but it would seem that you would use a different event to fire this - perhaps the Expand, Validate or Click event would be better? Not sure.

Here's the MSDN reference for the Treeview control, in case you don't already have it:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

RunriggerAuthor Commented:
been there also, as per MS in general their documentation is pretty poor and this doesn't help me any further.

Not sure what to do now as I haven't really learned anything that I didn't already know, do you get the points?

Happy to give them as it confirms that there isn't really anything I don't know, so will stop me exploring any further!
Helen FeddemaCommented:
It may be that the TreeView control is not the best interface for your needs -- how about using a MultiSelect listbox in place of the nodes that need to be checked?  Perhaps a TreeView could be used for the first level of selection, and then a listbox for the multi-select options.
Dale FyeCommented:
I played around with it a little bit in one of my apps and came up with this.  When I put the code in the NodeCheck event and stepped through it, I noticed that it was going false, but then went true again on exiting the event, so I assumed that either the Click or MouseUp event was causing it to revert to checked.

Private Sub tree_Activities_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, _
                                                           ByVal x As Long, ByVal y As Long)

    Dim tvw As MSComctlLib.TreeView
    Dim myNode As MSComctlLib.Node
    Set tvw = Me.tree_Activities.Object
    If tvw.HitTest(x, y) Is Nothing Then
        Exit Sub
        'Highlight the node the mouse is over
        Set myNode = tvw.HitTest(x, y)
    End If

    With myNode
        If Left(.Key, 2) = "FY" And .Checked = True Then
            .Checked = False
        End If
    End With
End Sub
RunriggerAuthor Commented:
Helpful, though not entirely what I wanted, thank you guys anyway
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.