Dim NodeX As Node Set NodeX = tvwData.SelectedItem If NodeX.Parent Is Nothing Then MsgBox "无父节点" End If
Dim nd As NodeSet nd = TreeView1.SelectedItem.ParentIf nd Is Nothing Then MsgBox "没有父结点" Else MsgBox "有父结点" End If
那请问如何知道他父结点的TEXT值那?
Set nd = TreeView1.SelectedItem.Parentnd.Text
判断该节点的子节点个数,node.Children=0
以前做測試用的代碼﹐寫的很亂﹐懶得改了。別問我﹐我什么都8知道。 Dim aa Dim al Dim u As Integer Dim father If Text1.Text = "" Then u = MsgBox("請輸入序列號﹗", vbExclamation, "輸入錯誤﹗") Text2.Text = "" Text1.SetFocus Exit Sub End If If Text2.Text = "" Then u = MsgBox("請輸入名稱﹗", vbExclamation, "輸入錯誤﹗") Text2.SetFocus Exit Sub End If
aa = use If aa = 0 Then Exit Sub End If If TreeView1.Nodes.Count > 0 Then For i = TreeView1.Nodes.Count To 1 Step -1 If TreeView1.Nodes(i).Key = Text1.Text & "j" Then u = MsgBox("已有此代號﹐請重新輸入!", vbExclamation, "輸入錯誤﹗") Text1.Text = "" Text2.Text = "" Text1.SetFocus Exit Sub End If Next End If father = Getkey() If Int(Val(Text1.Text)) = Val(Text1.Text) Then Set nodx = TreeView1.Nodes.Add(, , father & "j", Text2.Text, 1) Text1.Text = "" Text2.Text = "" Text1.SetFocus Else If TreeView1.Nodes.Count = 0 Then u = MsgBox("沒有父節點﹗", vbInformation, "查找出錯﹗") Text1.Text = "" Text2.Text = "" Text1.SetFocus Else al = 0 For i = 1 To TreeView1.Nodes.Count If father & "j" = TreeView1.Nodes(i).Key Then Set nodx = TreeView1.Nodes.Add(father & "j", tvwChild, Text1.Text & "j", Text2.Text, 3) Text1.Text = "" Text2.Text = "" Text1.SetFocus al = 1 Exit For End If Next i If al = 0 Then u = MsgBox("沒有父節點﹗", vbInformation, "查找出錯﹗") Text1.Text = "" Text2.Text = "" Text1.SetFocus End If End If End If Public Function Getkey() Dim d Dim e As String d = InStrRev(Form1.Text1.Text, ".", , 0) If d = 0 Then e = Left(Form1.Text1.Text, Len(Form1.Text1.Text)) Else e = Left(Form1.Text1.Text, d - 1) End If Getkey = e End Function
如果treeview的节点没有Parent,则 .Parent将出错,判断err.number也可
if node.parent is nothing then msgbox "没有parent" else msgbox "有" end if
Set NodeX = tvwData.SelectedItem
If NodeX.Parent Is Nothing Then
MsgBox "无父节点"
End If
MsgBox "没有父结点"
Else
MsgBox "有父结点"
End If
Dim aa
Dim al
Dim u As Integer
Dim father
If Text1.Text = "" Then
u = MsgBox("請輸入序列號﹗", vbExclamation, "輸入錯誤﹗")
Text2.Text = ""
Text1.SetFocus
Exit Sub
End If
If Text2.Text = "" Then
u = MsgBox("請輸入名稱﹗", vbExclamation, "輸入錯誤﹗")
Text2.SetFocus
Exit Sub
End If
aa = use
If aa = 0 Then
Exit Sub
End If
If TreeView1.Nodes.Count > 0 Then
For i = TreeView1.Nodes.Count To 1 Step -1
If TreeView1.Nodes(i).Key = Text1.Text & "j" Then
u = MsgBox("已有此代號﹐請重新輸入!", vbExclamation, "輸入錯誤﹗")
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
Exit Sub
End If
Next
End If
father = Getkey()
If Int(Val(Text1.Text)) = Val(Text1.Text) Then
Set nodx = TreeView1.Nodes.Add(, , father & "j", Text2.Text, 1)
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
Else
If TreeView1.Nodes.Count = 0 Then
u = MsgBox("沒有父節點﹗", vbInformation, "查找出錯﹗")
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
Else
al = 0
For i = 1 To TreeView1.Nodes.Count
If father & "j" = TreeView1.Nodes(i).Key Then
Set nodx = TreeView1.Nodes.Add(father & "j", tvwChild, Text1.Text & "j", Text2.Text, 3)
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
al = 1
Exit For
End If
Next i
If al = 0 Then
u = MsgBox("沒有父節點﹗", vbInformation, "查找出錯﹗")
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End If
End If
End If
Public Function Getkey()
Dim d
Dim e As String
d = InStrRev(Form1.Text1.Text, ".", , 0)
If d = 0 Then
e = Left(Form1.Text1.Text, Len(Form1.Text1.Text))
Else
e = Left(Form1.Text1.Text, d - 1)
End If
Getkey = e
End Function
msgbox "没有parent"
else
msgbox "有"
end if