How to select first tree node in treeview
If you have a treeview in sorted order how do you programaticlly select the first node ?
If I use: treeview1.SelectedItem = treeview1.Nodes(1) it selects the node but it is not currently the first node anymore due to sorting.
How can I select the first node in a treeview after nodes have been sorted ?
[320 byte] By [
kerv21] at [2007-11-18 13:41:47]

# 1 Re: How to select first tree node in treeview
Option Explicit
Private Sub Command1_Click()
'select the correct one
TvwSorted.Nodes(1).FirstSibling.Selected = True
'Or also:
' TvwSorted.Nodes(1).Root.Selected = True
TvwSorted.SetFocus
End Sub
Private Sub Form_Load()
Dim Counter As Integer
With TvwSorted
'add some nodes
For Counter = 0 To 10
'random: Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
.Nodes.Add , , , "a" & Chr(Int((50 * Rnd) + 40))
Next
.Sorted = True
'to show the wrong one is selected
.Nodes(1).Selected = True
End With
End Sub