关于VB 的treeview问题

来源:百度知道 编辑:UC知道 时间:2024/05/08 08:31:58
请问一下大家,我这段程序为什么总报错?
Private Sub Command1_Click()
If Text0.Text < > "" And Text1.Text < > "" Then '不允许建立零字节的父节点和子节点
CunZai = False
J = TreeView1.Nodes.Count
For I = 1 To TreeView1.Nodes.Count '检查新输入的父节点名称是否存在
If TreeView1.SelectedItem.Children > 0 Then
If Text0.Text = TreeView1.Nodes(I).Text Then CunZai = True
End If
Next I
If CunZai = True Then '若存在, 则在父节点下建立子节点
Set nodx = TreeView1.Nodes.Add(Text0.Text, tvwChild, "child" & J, Text1.Text, 3)
Else '若不存在,则建立父节点和子节点
Set nodx = TreeView1.Nodes.Add(, , Text0.Text, Text0.Text, 1)
Set nodx = TreeView1.Nodes.Add(Text0.Text, tvwChild, "child" & J, Text1.Text, 3)
End If
TreeView1.Refresh
ElseIf Text0.Text = "" Then MsgBox "请输入父节点名称!", vbInformation, "警告!"

Set nodx = TreeView1.Nodes.Add(, , Text0.Text, Text0.Text, 1)

应该这样吧?
Set nodx = TreeView1.Nodes.Add(, , " & Text0.Text & ", " & Text0.Text & ", 1)

子节点也这样处理。

Set nodx = TreeView1.Nodes.Add(, , Text0.Text, Text0.Text, 1)
要有一个根节点把,否则add不进去。

哇``太复杂了吧``呵呵``我是初学VB的``老师天天讲的课不难,但是就是不明白``为什么想写一个简单的游戏代码就不会啦```

你是不是在测试这个例子啊..我这个是没有图像列表的..

2个Text,名称分别是:text0, text1
1个treeview

Option Explicit

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

Private Sub Command1_Click()
If Text0.Text <> "" And Text1.Text <> "" Then '不允许建立零字节的父节点和子节点
CunZai = False
J = TreeView1.Nodes.Count
For I = 1 To TreeView1.Nodes.Count '检查新输入的父节点名称是否存在
If TreeView1.SelectedItem.Children > 0 Then
If Text0.Text = TreeView1.Nodes(I).Text Then CunZai = True
End If
Next I
If Cun