Keep values highlighted on two treeviews at the same time

Posted on 2011-10-17
Last Modified: 2012-05-12
Is it possible to keep values highlighted on two different  Treeviews at once? (I understand from code I know both are picked by the user, but in this problem I'm only talking about what the user sees.)

In the below graphic the user highlighted "Bisson, Terry" on the left treeview control, and then highlighted "Level5-Data2" on the right treeview control.  - They both stay highlighted as the user clicks a button or moves to other controls on a form.  That is what I need to do for a customer.

In reality with two treeviews in Access - when the user highlights  "Bisson, Terry" on the left treeview control, when they  highlight "Level5-Data2" on the right treeview control  "Bisson, Terry" is no longer highlighted on the left.  If they go to another control on the form, neither values are highlighted.

Again this is from the user prospective - what the user sees.

Any help is greatly appreciated.

Thanks in advance for your help.
Question by:LJG
    LVL 47

    Accepted Solution

    Try modifying the following two lines of code and putting them in the NodeClick event of the two trees.  Replace "tree_Activities" with the name of each of the trees on your form

        'Highlight the currently selected node
        Me.tree_Activities.DropHighlight = Nothing
        Me.tree_Activities.DropHighlight = Node

    These lines cause will highlight the currently selected node in the tree.
    LVL 33

    Assisted Solution

    This worked for me.
    Private Sub tvwOther_NodeClick(ByVal Node As Object)
        tvwOther.DropHighlight = tvwOther.Object.SelectedItem
    End Sub
    Private Sub tvwBooks_NodeClick(ByVal Node As Object)
        tvwBooks.DropHighlight = tvwBooks.Object.SelectedItem
    End Sub

    Open in new window

    Where the two treeviews were tvwOther and tvwBooks.

    Did act a bit strange sometimes though.
    LVL 2

    Author Comment


    Thanks so much for the answers.  I used both snippets to make things work.  Because I'm going to be creating a number of forms with Treeviews, I put some code in a module so that it would be easy to call.  (Some would say that's over coding.)

    So --- Create a public function in a module --> TreeView_KeepNodeSelected()

    Then call the function on NodeClick event.

    For those of you new to controls like treeview, you are going to go to the Treeview control, look at properties, and wonder where the NodeClick event is.  Join the club.

    Just go to your code for the form, pick the Treeview from the left pull down, and you will have all your events in the right pull down.  (Same is true for any control)

    Hope this helps someone.

    Private Sub TreeViewCtl_2_NodeClick(ByVal Node As Object)
    	Call TreeView_KeepNodeSelected
    End Sub '-------------------------------------------------
    Public Function TreeView_KeepNodeSelected() '-------------
    Dim ctlTree  As Control
    	Set ctlTree = screen.ActiveControl
    	ctlTree.DropHighlight = ctlTree.Object.SelectedItem
    End Function '--------------------------------------------

    Open in new window


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
    Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
    In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now