1个回答
展开全部
按照里面的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" & J, _
txt(1).Text, 3)
End If
TreeView1.Refresh
ElseIf txt(0).Text = "" Then MsgBox "请输入父节点名称!", vbInformation, "警告!"
'系统提示
ElseIf txt(1).Text = "" Then MsgBox "请输入子节点名称!", vbInformation, "警告!"
End If
End Sub
Private Sub Command2_Click()
For I = 1 To TreeView1.Nodes.Count
TreeView1.Nodes(I).Expanded = True '展开所有节点
Next I
End Sub
Private Sub Command3_Click()
For I = 1 To TreeView1.Nodes.Count
TreeView1.Nodes(I).Expanded = False '收起所有节点
Next I
End Sub
Private Sub Command4_Click()
TreeView1.Sorted = True '排列顺序
End Sub
Private Sub Command5_Click()
If TreeView1.SelectedItem.Index <> 1 Then
TreeView1.Nodes.Remove TreeView1.SelectedItem.Index '删除选定的节点
End If
End Sub
Private Sub Command6_Click()
End '退出程序
End Sub
Private Sub Form_Load()
TreeView1.LineStyle = tvwTreeLines '在兄弟节点和父节点之间显示线
TreeView1.ImageList = ImageList1 '链接图像列
TreeView1.Style = tvwTreelinesPlusMinusPictureText
'树状外观包含全部元素
Set nodx = TreeView1.Nodes.Add(, , "aaaaa", "aaaaa", 1)
'建立名称为"aaaaa"的父节点,选择索引为1的图像
Set nodx = TreeView1.Nodes.Add("aaaaa", tvwChild, "child01", "收件箱", 3)
'在"aaaaa"父节点下建立"收件箱"子节点,选择索引为3的图像
Set nodx = TreeView1.Nodes.Add("aaaaa", tvwChild, "child02", "发件箱", 3)
'在"aaaaa"父节点下建立"发件箱"子节点,选择索引为3的图像
CunZai = False
End Sub
Private Sub TreeView1_Expand(ByVal Node As MSComctlLib.Node)
Node.ExpandedImage = 2 '节点被展开时,选择索引为2的图像
End Sub
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
If TreeView1.SelectedItem.Children = 0 Then '检查是否有子节点,0为无
For I = 1 To TreeView1.Nodes.Count
If TreeView1.Nodes(I).Selected Then
MsgBox "您选择的是:“" & TreeView1.Nodes(I).FullPath & "”子节点!"
'系统提示
End If
Next I
End If
End 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" & J, _
txt(1).Text, 3)
End If
TreeView1.Refresh
ElseIf txt(0).Text = "" Then MsgBox "请输入父节点名称!", vbInformation, "警告!"
'系统提示
ElseIf txt(1).Text = "" Then MsgBox "请输入子节点名称!", vbInformation, "警告!"
End If
End Sub
Private Sub Command2_Click()
For I = 1 To TreeView1.Nodes.Count
TreeView1.Nodes(I).Expanded = True '展开所有节点
Next I
End Sub
Private Sub Command3_Click()
For I = 1 To TreeView1.Nodes.Count
TreeView1.Nodes(I).Expanded = False '收起所有节点
Next I
End Sub
Private Sub Command4_Click()
TreeView1.Sorted = True '排列顺序
End Sub
Private Sub Command5_Click()
If TreeView1.SelectedItem.Index <> 1 Then
TreeView1.Nodes.Remove TreeView1.SelectedItem.Index '删除选定的节点
End If
End Sub
Private Sub Command6_Click()
End '退出程序
End Sub
Private Sub Form_Load()
TreeView1.LineStyle = tvwTreeLines '在兄弟节点和父节点之间显示线
TreeView1.ImageList = ImageList1 '链接图像列
TreeView1.Style = tvwTreelinesPlusMinusPictureText
'树状外观包含全部元素
Set nodx = TreeView1.Nodes.Add(, , "aaaaa", "aaaaa", 1)
'建立名称为"aaaaa"的父节点,选择索引为1的图像
Set nodx = TreeView1.Nodes.Add("aaaaa", tvwChild, "child01", "收件箱", 3)
'在"aaaaa"父节点下建立"收件箱"子节点,选择索引为3的图像
Set nodx = TreeView1.Nodes.Add("aaaaa", tvwChild, "child02", "发件箱", 3)
'在"aaaaa"父节点下建立"发件箱"子节点,选择索引为3的图像
CunZai = False
End Sub
Private Sub TreeView1_Expand(ByVal Node As MSComctlLib.Node)
Node.ExpandedImage = 2 '节点被展开时,选择索引为2的图像
End Sub
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
If TreeView1.SelectedItem.Children = 0 Then '检查是否有子节点,0为无
For I = 1 To TreeView1.Nodes.Count
If TreeView1.Nodes(I).Selected Then
MsgBox "您选择的是:“" & TreeView1.Nodes(I).FullPath & "”子节点!"
'系统提示
End If
Next I
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |