急急急急!TreeView控件中,如何设置能让一个有Child的Node的Checked=True(False)后,他的全部Child Node的Checked都等于True(False)

MonkeyLin 2001-10-07 09:53:09
...全文
161 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
brrr 2001-10-07
  • 打赏
  • 举报
回复
补充一下,上面的代码不管tree有几层,都可以通过递归实现同步的,大侠如果使用解决了问题(也有可能不爽),别忘了给小弟提提建议哦,我还是菜鸟
brrr 2001-10-07
  • 打赏
  • 举报
回复
给你的源码是让所有的node同步
Private Sub setchildrennodes(node As node)
If node Is Nothing Then Exit Sub
If issystemcontrol = True Then Exit Sub
Dim child As node
Set child = node.child
If child Is Nothing Then Exit Sub
Dim nodecounter As Integer
If node.Children = 0 Then Exit Sub
For nodecounter = 1 To node.Children
issystemcontrol = True
child.Checked = node.Checked
issystemcontrol = False
Set child = child.Next
Call setchildrennodes(child)
Next
End Sub

Private Sub setparentnodes(node As node)
If node Is Nothing Then Exit Sub
Dim parentnode As node
Dim nownode As node
Dim flag As Boolean
Dim counter As Integer
flag = True
Set parentnode = node.Parent
If parentnode Is Nothing Then Exit Sub
Set nownode = node.FirstSibling
For counter = 1 To parentnode.Children
flag = flag And nownode.Checked
Set nownode = nownode.Next
Next
issystemcontrol = True
parentnode.Checked = flag
issystemcontrol = False
Call setparentnodes(parentnode)
End Sub

在发生点击事件的时候调用就可以了,保证子母节点的同步
MonkeyLin 2001-10-07
  • 打赏
  • 举报
回复
chileNode.Parent.index=对象变量或块with变量未设置
cs_netwalker 2001-10-07
  • 打赏
  • 举报
回复
dim childNode as Node
dim thisIndex as long
thisIndex=当前选中的(或取消的)Node.index
for each childNode in TreeView1.nodes
if chileNode.Parent.index=thisIndex then
chileNode.Checked=True '(or False)
end if
next
大概如此,你试试看吧。
MonkeyLin 2001-10-07
  • 打赏
  • 举报
回复
哦!谢谢各位^^
progame 2001-10-07
  • 打赏
  • 举报
回复
不过你的东西还是用递归实现好一点

具体的方法你去看一下算法方面的书吧,很基本的
progame 2001-10-07
  • 打赏
  • 举报
回复
其实我上面没有用到递归,但原理是一样的
MonkeyLin 2001-10-07
  • 打赏
  • 举报
回复
解释一下什么叫递归
progame 2001-10-07
  • 打赏
  • 举报
回复
递归一下嘛,小猴子,给你一段我的代码参考一下:
Private Function DelNode(mNode As node) As Boolean
'删除一个节点和此节点下的所有节点
Dim nodX As node
Dim nodTmp As node
'/*如果当前节点下无任何子节点,则一步到位地删除
If mNode Is Nothing Then Exit Function
If mNode.Key = "N0" Then Exit Function
If MsgBox("是否确认删除此节点?", vbInformation + vbOKCancel, "提示") = vbCancel Then
Exit Function
End If
If mNode.Child Is Nothing Then
Call DelSngNode(mNode)
Exit Function
End If
Set nodX = mNode.Child
Do While Not nodX.Key = (mNode.Key)
If nodX.Child Is Nothing Then
Set nodTmp = nodX.Parent
Call DelSngNode(nodX)
Set nodX = nodTmp
Else
Set nodX = nodX.Child
End If
Loop
Call DelSngNode(nodX)
End Function

Private Function DelSngNode(mNode As node) As Boolean
'仅删除一个节点,供DelNOde调用
Dim l As Long
'/*数据库中删除此条记录
l = CLng(Right(mNode.Key, Len(mNode.Key) - 1))
ac.Execute "delete from data where num=" & l
'/*删除此节点
tvFile.Nodes.Remove (mNode.Key)
End Function

为删除用的,本来直接删除一个节点就行了,
但我的节点是和数据库记录关联的,要去删除所有的记录,
所以成了上面这样子了,你应该可以看明白吧:)

1,451

社区成员

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

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