5

The desktop application I'm migrating makes heavy use of a TreeView control, and many calls to TreeNode.FirstSibling, e.g.

'UPGRADE_ISSUE: MSComctlLib.Node property tvTreeView.SelectedItem.FirstSibling was not upgraded.
If tvTreeView.SelectedNode.FirstSibling.Index = 1 Then
...
End If

Is there an equivalent function to use?

R.J. Dunnill
  • 2,049
  • 3
  • 10
  • 21
brasskazoo
  • 76,030
  • 23
  • 64
  • 76
  • Im assuming VB6 had the index of the first node be 1? (not zero based) Then wouldnt the above IF statement ALWAYS be true? – Neil N Feb 26 '09 at 23:21
  • I think you're right! But its not the only use of it so the problem remains even after removing those sort of programming mistakes.. Maybe I should have re-written from scratch.. – brasskazoo Feb 26 '09 at 23:38
  • @brass - Read this if you're thinking about re-writting http://www.joelonsoftware.com/articles/fog0000000069.html – Gavin Miller Feb 27 '09 at 15:40

2 Answers2

7

Well to have a sibling it has to have a parent, so you could do

myTreeNode.Parent.FirstNode

Or you could do

myTreeNode.Parent.Nodes[0]

EDIT: and for last sibling:

myTreeNode.Parent.LastNode
TAbdiukov
  • 1,185
  • 3
  • 12
  • 25
Neil N
  • 24,862
  • 16
  • 85
  • 145
0

I could be wrong but isn't "FirstChild", or FirstParent. Alternatively, NextNode, which should iterate through siblings.

Ash
  • 24,276
  • 34
  • 107
  • 152