Clear Focus in Treeview

gray

Registered User.
Local time
Today, 14:01
Joined
Mar 19, 2007
Messages
578
Hi

Access 2007 SP3
WinXPPro SP3

A Treeview's focus and selected item are not always one and the same. This is because the Expand/Collapse symbol can be clicked whilst leaving the focus on another node in the tree.

What I would like to do in these circumstances is to "clear" the focus from the highlighted Treeview node... i.e. remove the blue highlight from it (or temporarily change the highlight colour to white). I don't want to move the focus as such, just clear it. When the node is re-clicked or another node is clicked, I want the highlighting to carry on as normal.

Any idea how this can be done please? I thought it would be treeview.drophighlight but that does something entirely different.

Thanks
 
I assume you are referring to the TreeView control found in the Microsoft Windows Common Controls 6.0 (SP6) MSComCtl.ocx file, correct?

I make use of that control, and was bothered by the "fly away" behavior. I do not add/delete entries... just statically populate it when the form opens.

Since the control did not have a Double Click event, I had to use a Select button instead. Here is a sample of the code I have in my Select button.

Code:
Private Sub btnSelect_Click()
On Error GoTo Err_btnSelect_Click

  Dim oNode As MSComctlLib.Node
  Dim strThisKey As String

  Set oNode = Me.tvPickListAdmin.SelectedItem
  strThisKey = oNode.Key

'  Debug.Print "Node clicked with Key: " & strThisKey

  Select Case strThisKey
    'AOE entries
    Case "G1N1"
      Call AOECmplStatus_Click
    Case "G1N2"
      Call AOEFixtureTeamLocation_Click
    Case "G1N3"
      Call AOEFixtureType_Click
'snip...
  End Select

[B][COLOR=Blue]  'Return focus to the TreeView control
  Me.tvPickListAdmin.SetFocus[/COLOR][/B]

Exit_btnSelect_Click:
  Set oNode = Nothing

  Exit Sub

Err_btnSelect_Click:
  Call errorhandler_MsgBox("Form: " & Me.Module.Name & ", Subroutine: btnSelect_Click()")
  Resume Exit_btnSelect_Click

End Sub
 
Hi - thanks for the reply...

I assume you are referring to the TreeView control found in the Microsoft Windows Common Controls 6.0 (SP6) MSComCtl.ocx file, correct?
Yes, that assumption is correct... apologies, I should have said that to start with. :)

As suggested, I dabbled with the focus... during the Collapse event I set the focus to an Exit command button and then re-focused to the Treeview control... alas the collapsed record in the Treeview still remains highlighted.

It's not a massive issue...but I use the highlighting to indicate to the user which record in the Treeview is presently summarised in another control... when the collapse has taken place I clear that other control ... but because the highlight is still present it could mislaed the user into thinking there's no corresponding detail....

I had wondered if the focus highlight in the treeview could be set to white ...until another record is clicked?
 
As suggested, I dabbled with the focus... during the Collapse event I set the focus to an Exit command button and then re-focused to the Treeview control... alas the collapsed record in the Treeview still remains highlighted.

All right, I think I am now following you...

gggrrrr.... And in clicking around my TreeView control, I ended up stumbling upon the ability to rename TreeView nodes. Now I am interested in setting the TreeView read-only in my case, since it is a program menu.

I had wondered if the focus highlight in the treeview could be set to white ...until another record is clicked?

I will check into that while seeking how to make the TreeView control read-only. BRB...
 
gggrrrr.... And in clicking around my TreeView control, I ended up stumbling upon the ability to rename TreeView nodes. Now I am interested in setting the TreeView read-only in my case, since it is a program menu.

Properties of the TreeView control \ Other tab \ Label Edit property, for Read-Only it appears to need to be set to 1 (tvwManual).

Now off to research your observation...
 
Have you tried VBA sending the Form .SetFocus to the TreeView control and then next sending the TreeView control a .Requery event?

I can not seem to be able to get the TreeView control to return an inaccurate Node Key.
 
Hi

And in clicking around my TreeView control, I ended up stumbling upon the ability to rename TreeView nodes

I thought I'd better check my treeview edit setting ... fortunately it was set to 1 already but it's a good tip.

Whilst in the treeview properties* I noticed a 'hide selection' setting... sounded a promising start but it does not seem to hide either the selection or focus)

Have you tried VBA sending the Form .SetFocus to the TreeView control and then next sending the TreeView control a .Requery event?

I do 'lazy' population of my Treeview... so... on expansion of a node SQL is built which returns a recordset. This is looped to build child nodes of the expanded node - i.e. I can't do a re-query.

I have found some code which refers to:-
.HighlightColorIndex = blah blah
but this relies upon applying it to the correct windows pane and then the correct control within the pane ... a little too advanced for my VB skills.... so I still a little stuck.

Thanks




* If you are reading this and don't know how to get to those properties ... put your form in design mode then double-click on white-space inside the treeview... and do this below any 'ghost' records shown in the treeview
 
Last edited:
I do 'lazy' population of my Treeview...

Aaaahhhh, THAT is the difference then. I populate my TreeView control all at once, and one time only.

* If you are reading this and don't know how to get to those properties ... put your form in design mode then double-click on white-space inside the treeview... and do this below any 'ghost' records shown in the treeview

Is this the same UI as Property Sheet \ Other tab \ Custom property \ click the [...] button?
 
Hi

Is this the same UI as Property Sheet \ Other tab \ Custom property \ click the [...] button?

I think when I added mine, I could not find how to add an imagelist to the treeview for love nor money.... I stumbled across the 'extra' properties afforded by the double-click method (as per my footnote) purely by accident.... In fact I still can't see a way to do that from the 'Other' tab of the Properties sheet? Ah.. the wonderful World of Microsoft ... obsfucation-by-design... :)
 
Hi

Allied to this problem is an associated ListView. This Listview is populated ith respect to the selected node in the treeview. In this Listview, the first record added becomes the selected item (by default). This is indicated by a grey highlight. Since this could be confusing to the end user, once populated I clear the listview's selected item using:-

Set Lv=Me.lvListView.Object
Set Lv.SelectedItem = Nothing
Set Lv.DropHighlight = Nothing

However, as you will see from the attached jpg, there is still a grey highlight on the first listitem. If I click in the white-space in the ListView it clears the grey highligt but I've been unable to do this programmatically with .setfocus calls?

Any idea how I 'kick' the Listview in VBA? I've also tried re-paint but alas no joy..... thanks
 

Attachments

  • LV_After_Adding_ListItems.JPG
    LV_After_Adding_ListItems.JPG
    25.3 KB · Views: 247
Last edited:
Hi

Well I think I've resolved the main part of my issue... i.e. clearing the focus highlight down from a Treeview.

This can be cleared whenever you deem necessary by simply
Code:
Dim Tv As Treeview

Set Tv=Me.tvTreeView.Object 
Set Tv.SelectedItem = Nothing
Set Tv.DropHighlight = Nothing

Unfortunately, my attempts to do this were thwarted by my own code... hidden deep down in my node.collapse event I called

me.tvTreeview.SelectedItem = node (node is given by the event parms)

so I was clearing the focus and immediately resetting it again ..whoops... .

But I still have to figure out my Listview question. Highlighting selections works perfectly with the exception that I have to click in white-space in order to get the Listview to display correct selections...?

To illustrate I've added two more attachments... I set the selecteditem and drophighlight to nothing and the Listview appears as in 'before_clicking'.. note the grey highlight is present.... I click in the Listview's white-space and the grey disappears as in 'after_clicking'??. Setting the focus with VB does have this effect??

Thanks
 

Attachments

  • LV_before_clicking.JPG
    LV_before_clicking.JPG
    17.6 KB · Views: 228
  • LV_after_clicking.JPG
    LV_after_clicking.JPG
    16.2 KB · Views: 218

Users who are viewing this thread

Back
Top Bottom