问题描述
- 在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
解决方案
If tn.Text Like ""*"" & text.Trim() & ""*"" Then
Like需要有通配符啊。
解决方案二:
改过以后有效果了,之前点查找按钮没有反应,现在是当查找到值有类似情况的时候,提示NODE为空,不知道是哪里出问题了,请帮忙看看
解决方案三:
找到问题了,再次循环到根节点的时候,提示根节点是NOTHING,出错了,我把 ISDBNULL 该成NULL 后
If Not node Is Nothing Then
node.Expand()
shownodes(node.Parent)
End If
时间: 2024-12-03 05:08:16