I'm trying to write some code that will highlight a node in a treeview control when you move your mouse over it or on the same vertical position (The same as the drop down combo list in the Windows Explorer).

This is what I've done so far:

Private Sub Form_Load()

Dim nodCur As Node

' Add some nodes
With TreeView1.Nodes
Set nodCur = .Add(, , , "One")
Set nodCur = .Add(nodCur.Index, tvwChild, , "Two")
Set nodCur = .Add(nodCur.Index, tvwChild, , "Three")
Set nodCur = .Add(, , , "Four")
Set nodCur = .Add(, , , "Five")
Set nodCur = .Add(nodCur.Index, tvwChild, , "Six")
Set nodCur = .Add(, , , "Seven")
Set nodCur = .Add(nodCur.Index, tvwChild, , "Eight")
Set nodCur = .Add(nodCur.Index, tvwChild, , "Nine")
Set nodCur = .Add(nodCur.Index, tvwChild, , "Ten")
End With

' Tidy up
Set nodCur = Nothing

End Sub

Private Sub TreeView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)

Dim lngCounter As Long
Dim nodCur As Node

For lngCounter = 0 To TreeView1.Width Step 180

Set nodCur = TreeView1.HitTest(lngCounter, y)

If Not nodCur Is Nothing Then

Set TreeView1.DropHighlight = nodCur
Exit For
End If

Next

' Tidy up
Set nodCur = Nothing

End Sub


It works fine, until the horizontal scrollbar is displayed, because I can no longer use 0 to the Treeview1.Width as the area to search for the node, as the area is now wider.

How can I find out what the scrollable width of a treeview is, or is there a better way of doing this?


Cheers