I'm bad with recursing, but pretty good with cursing.

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.

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.  
  31.  
  32.     End Function
  33.  
  34.     Public Function SearchChildNodes(ByRef tn As TreeNode, ByVal strID As String) As TreeNode
  35.  
  36.         Dim tnTemp As TreeNode
  37.         Dim tnRec As TreeNode
  38.  
  39.  
  40.         For Each tnTemp In tn.Nodes
  41.             If tnTemp.ID = strID Then
  42.                 Return tnTemp
  43.             Else
  44.                 If (tnTemp.Nodes.Count > 0) Then
  45.                     tnRec = SearchChildNodes(tnTemp, strID)
  46.                     If Not tnRec Is Nothing Then
  47.                         Return tnRec
  48.                     End If
  49.                 End If
  50.             End If
  51.         Next
  52.  
  53.     End Function

Call it like so:

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

Although I'll be submitting it to the codebank, anyone see any scope for improvements?