Here's what I came up with to recurse through a treeview, given an ID value for a node, and to return it's NodeIndex property. (This is the IE Web Control Treeview which is not supported by Microsoft)

VB Code:
  1. Public Function FindAndReturnNodeIndex(ByRef tnc As TreeNodeCollection, ByVal strID As String) As String
  2.  
  3.         Dim tnRec As TreeNode
  4.         Dim strTemp As String
  5.         Dim tnRet As TreeNode
  6.  
  7.  
  8.  
  9.  
  10.         For Each tnTemp As TreeNode In tnc
  11.             If tnTemp.ID = strID Then
  12.                 Return tnTemp.GetNodeIndex
  13.                 Exit Function
  14.             End If
  15.         Next
  16.  
  17.  
  18.  
  19.         For Each tnRec In tnc
  20.             tnRet = SearchChildNodes(tnRec, strID)
  21.             If Not tnRet Is Nothing Then
  22.                 Return tnRet.GetNodeIndex
  23.             End If
  24.  
  25.         Next
  26.  
  27.        
  28.  
  29.  
  30.     End Function
  31.  
  32.  
  33.  
  34.  
  35.     Public Function SearchChildNodes(ByRef tn As TreeNode, ByVal strID As String) As TreeNode
  36.  
  37.         Dim tnTemp As TreeNode
  38.         Dim tnRec As TreeNode
  39.  
  40.  
  41.         For Each tnTemp In tn.Nodes
  42.             If tnTemp.ID = strID Then
  43.                 Return tnTemp
  44.             Else
  45.                 If (tnTemp.Nodes.Count > 0) Then
  46.                     tnRec = SearchChildNodes(tnTemp, strID)
  47.                     If Not tnRec Is Nothing Then
  48.                         Return tnRec
  49.                     End If
  50.                 End If
  51.             End If
  52.         Next
  53.  
  54.     End Function

Call it like so:

VB Code:
  1. Dim asdfy As String = FindAndReturnNodeIndex(Me.tvFamilyTree.Nodes, "TimeCard2")