2 allbluekos allbluekos 于 2015.06.11 16:08 提问

在TREEVIEW中查找值等于TEXTBOX的值

如题,在TEXTBOX中输入一个值,按查找按钮,在树中找到并高亮显示,没有实现,请帮忙看看如下代码,看怎么修改:
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim tnc As TreeNode
For Each tnc In TreeView1.Nodes
nextnodes(tnc, TextBox7.Text)
Next
End Sub
Public Sub nextnodes(ByVal node As TreeNode, ByVal text As String)
Dim tn As TreeNode
For Each tn In node.Nodes
If tn.Text Like text.Trim() Then
tn.BackColor = Drawing.Color.YellowGreen
shownodes(tn)
End If
nextnodes(tn, text)
Next
End Sub
Public Sub shownodes(ByVal node As TreeNode)
If IsDBNull(node) = False Then
node.Expand()
shownodes(node.Parent)
End If
End Sub
图片说明

3个回答

Tiger_Zhao
Tiger_Zhao   Rxr 2015.06.11 17:10
已采纳

If tn.Text Like "*" & text.Trim() & "*" Then
Like需要有通配符啊。

allbluekos
allbluekos   2015.06.11 17:30

改过以后有效果了,之前点查找按钮没有反应,现在是当查找到值有类似情况的时候,提示NODE为空,不知道是哪里出问题了,请帮忙看看图片说明

allbluekos
allbluekos   2015.06.11 17:47

找到问题了,再次循环到根节点的时候,提示根节点是NOTHING,出错了,我把 ISDBNULL 该成NULL 后

If Not node Is Nothing Then
node.Expand()
shownodes(node.Parent)
End If图片说明

Csdn user default icon
上传中...
上传图片
插入图片