VB.NET中怎么给TreeView的父节点添加相对应的子节点?求助各位!
请问我应该怎么做,最好能给出类似的代码。谢谢! 展开
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
忘了说我是绑定了数据库的 请问下需要有哪些地方不一样吗 我才刚刚开始学很多不懂 麻烦你了
绑定了数据库没关系呀,你只要参考程序中是如何查找和添加节点的代码