经过测试是可以正常工作的,但是要注意,因为默认情况下直接点右键是不能实现选中的,所以你要先左键选中,再点右键。
龙岗网站建设公司成都创新互联公司,龙岗网站设计制作,有大型网站制作公司丰富经验。已为龙岗上千提供企业网站建设服务。企业网站搭建\外贸营销网站建设要多少钱,请找那个售后服务好的龙岗做网站的公司定做!
TreeView的SelectedNode属性获取或设置当前选择的节点。
TreeView1.SelectedNode = TreeView1.Nodes(1) '选择第二个节点
Private Sub TreeView1_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
If e.Node.Text = "abc" Then
'你的代码
End If
End SUb
Public Class Form1
Dim node(5) As TreeNode
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim root As TreeNode
With TreeView1
.Nodes.Clear()
.ShowLines = True
.ShowPlusMinus = True
.ShowRootLines = True
root = .Nodes.Add("仓库") '增加根节点
.SelectedNode = root '在此根节点下添加子节点
For i = 1 To 6
node(i - 1) = .SelectedNode.Nodes.Add(i.ToString "号仓库")
Next
.ExpandAll()
End With
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If Val(TextBox1.Text) = 100 And Val(TextBox1.Text) = 699 Then
node(Val(TextBox1.Text) \ 100 - 1).Nodes.Add(TextBox1.Text)
End If
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
If Val(TextBox2.Text) = 1000000 And Val(TextBox2.Text) = 6999999 Then
For Each child As TreeNode In node(Val(TextBox2.Text) \ 1000000 - 1).Nodes
If child.Text = TextBox2.Text.Substring(1, 3) Then
child.Nodes.Add(TextBox2.Text)
Exit For
End If
Next
End If
End Sub
End Class