Public Function FindNode(tvw As TreeView, strFind As String, intSearchType As eSearchType) As Boolean
'Search for a node using the TAG property.
'TAG property filled like this: node.Tag=First|Second|Third|Fourth|Fifth field
'
' This function first collapses the treeview and then shows the found items in a different color.
Dim strTag As String
Dim lngcount As Long
Dim blnFound As Boolean
Dim blnActive As Boolean
Dim intSearchField As Integer
Dim strGlobalSearch As String
blnFound = False
FindNode = blnFound
If strFind = "" Then Exit Function
Select Case intSearchType
Case eSearchType.Pillar
intSearchField = 3
Case eSearchType.Fuid
intSearchField = 4
Case eSearchType.Section
intSearchField = 5
Case Else 'eSearchType.Text
intSearchField = 0 'Search through complete tag
End Select
For lngcount = 1 To tvw.Nodes.Count
tvw.Nodes(lngcount).Expanded = False
strTag = tvw.Nodes(lngcount).Tag
strGlobalSearch = Mid$(strTag, InStr(1, strTag, "|"))
blnActive = CBool(GetPart(strTag, "|", 2))
If InStr(1, strGlobalSearch, strFind) Then Search globally
If InStr(1, GetPart(strTag, "|", intSearchField), strFind) Then 'Narrow the search
blnFound = True
If blnActive Then
tvw.Nodes(lngcount).ForeColor = vbBlue 'Found
Else
tvw.Nodes(lngcount).ForeColor = RGB(255, 140, 0) 'DarkOrange'vbGreen 'Found but not active.
tvw.Nodes(lngcount).Image = "BottomKey"
End If
tvw.Nodes(lngcount).EnsureVisible
End If
Else
If blnActive Then 'Reset previously changed nodecolor.
tvw.Nodes(lngcount).ForeColor = vbBlack 'Active
Else
tvw.Nodes(lngcount).ForeColor = vbRed 'Not active.
tvw.Nodes(lngcount).Image = "BottomKey"
End If
End If
Next lngcount
FindNode = blnFound
End Function