关于VB中TreeView控件使用样例

来源:百度知道 编辑:UC知道 时间:2024/05/08 03:13:08
请那位高手给我一个使用TreeView控件使用样例

按照里面的SUB相应地添加控件.
如果满意我们回答,请采纳.谢谢
Option Explicit

Dim I As Integer
Dim J As Integer
Dim nodx As Node
Dim CunZai As Boolean '定义变量

Private Sub Command1_Click()
If txt(0).Text <> "" And txt(1).Text <> "" Then '不允许建立零字节的父节点和子节点
CunZai = False
J = TreeView1.Nodes.Count
For I = 1 To TreeView1.Nodes.Count '检查新输入的父节点名称是否存在
If TreeView1.SelectedItem.Children > 0 Then
If txt(0).Text = TreeView1.Nodes(I).Text Then CunZai = True
End If
Next I
If CunZai = True Then '若存在, 则在父节点下建立子节点
Set nodx = TreeView1.Nodes.Add(txt(0).Text, tvwChild, "child" & J, _
txt(1).Text, 3)
Else ',若不存在,则建立父节点和子节点
Set nodx = TreeView1.Nodes.Add(, , txt(0).Text, txt(0).Text, 1)
Set nodx = TreeView1.Nodes.Add(txt(0).Text, tvwChild, "child" &