请问如何判断TREEVIEW中一个子结点是否有父结点?

0551 2003-09-18 05:09:35
请问如何判断TREEVIEW中一个子结点是否有父结点?
...全文
95 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuwuyu 2003-09-19
  • 打赏
  • 举报
回复
if node.parent is nothing then
msgbox "没有parent"
else
msgbox "有"
end if
whjwsy 2003-09-18
  • 打赏
  • 举报
回复
如果treeview的节点没有Parent,则 .Parent将出错,判断err.number也可
daisy8675 2003-09-18
  • 打赏
  • 举报
回复
以前做測試用的代碼﹐寫的很亂﹐懶得改了。別問我﹐我什么都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
lanWay 2003-09-18
  • 打赏
  • 举报
回复
判断该节点的子节点个数,node.Children=0
射天狼 2003-09-18
  • 打赏
  • 举报
回复
Set nd = TreeView1.SelectedItem.Parent

nd.Text
dsclub 2003-09-18
  • 打赏
  • 举报
回复
.Parent.Text
dsclub 2003-09-18
  • 打赏
  • 举报
回复
.Parent.Text
hxy2003 2003-09-18
  • 打赏
  • 举报
回复
对啊。
0551 2003-09-18
  • 打赏
  • 举报
回复
那请问如何知道他父结点的TEXT值那?
射天狼 2003-09-18
  • 打赏
  • 举报
回复
楼上快啊~~
射天狼 2003-09-18
  • 打赏
  • 举报
回复
Dim nd As Node

Set nd = TreeView1.SelectedItem.Parent

If nd Is Nothing Then
MsgBox "没有父结点"
Else
MsgBox "有父结点"
End If
lilaclone 2003-09-18
  • 打赏
  • 举报
回复
Dim NodeX As Node
Set NodeX = tvwData.SelectedItem
If NodeX.Parent Is Nothing Then
MsgBox "无父节点"
End If

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧