第几级节点是型号,第几级节点是规格?下面的代码,任意匹配的,没有涉及到层级关系。
Dim arr() As String = e.Form.Controls("型号规格").text.split(" ")
Dim xh,gg As String
If arr.length > 0 Then
xh = arr(0)
End If
If arr.Length > 1 Then
gg = arr(1)
End If
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim Start As Integer
Dim idx As Integer = - 1
If trv.SelectedNode IsNot Nothing Then '获取当前节点位置.
Dim fullpath As String = trv.SelectedNode.FullPath
For i As Integer = 0 To trv.AllNodes.count - 1
If trv.AllNodes(i).fullpath = fullpath Then
Start = i
Exit For
End If
Next
End If
For i As Integer = Start + 1 To trv.AllNodes.count - 1 '从当前节点的下一个节点开始查找
Dim nd As WinForm.TreeNode = trv.AllNodes(i)
If gg > "" Then
If nd.text.IndexOf(gg) >= 0 Then
If xh > "" Then
If nd.ParentNode.Text.IndexOf(xh) >= 0 Then
trv.SelectedNode = nd
nd.EnsureVisible
idx = i '将找到的位置复制给变量idx
Exit For
End If
Else
trv.SelectedNode = nd
nd.EnsureVisible
idx = i '将找到的位置复制给变量idx
Exit For
End If
End If
Else
If xh > "" Then
If nd.Text.IndexOf(xh) >= 0 Then
trv.SelectedNode = nd
nd.EnsureVisible
idx = i '将找到的位置复制给变量idx
Exit For
End If
End If
End If
Next
If idx = -1 Then
msgbox("找完了")
End If
trv.Select()