allbluekos
allbluekos
2015-06-11 08:08
采纳率: 88.5%
浏览 1.6k
已采纳

在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 2015-06-11 09:10
    已采纳

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

    点赞 评论
  • allbluekos
    allbluekos 2015-06-11 09:30

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

    点赞 评论
  • allbluekos
    allbluekos 2015-06-11 09:47

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

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

    点赞 评论

相关推荐