以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  多选目录树复选框的反选问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=177716)

--  作者:采菊东篱下
--  发布时间:2022/5/31 21:15:00
--  多选目录树复选框的反选问题

图片点击可在新窗口打开查看此主题相关图片如下:qq图片20220531210519.png
图片点击可在新窗口打开查看

Dim trv1 As WinForm.TreeView = e.Form.Controls("TreeView1")
For Each nd1 As WinForm.TreeNode In e.Node.AllNodes \'清除子节点的选中标记
    nd1.Checked = e.Node.Checked
Next
If e.Node.Checked = False Then
    Dim pd As WinForm.TreeNode = e.Node.ParentNode
    If pd IsNot Nothing Then
        pd.Checked = False
    End If
Else 
    Dim pd As WinForm.TreeNode = e.Node.ParentNode
    If pd IsNot Nothing Then
        For Each nd2 As WinForm.TreeNode In pd.Nodes
            nd2.Checked = True
        Next
        pd.Checked = True
    End If
End If
我希望勾选所在子字节,父字节同步勾选,但子字节有一个没勾选的父字节都不被勾选,帮助里介绍的只做到勾选父字节时子字节同步勾选,反之亦然,取消子字节勾选,同步取消父字节勾选,没做到我问的效果,红色标注的代码做到了勾选子字节同步勾选父字节,但勾一个父字节都同步勾选了,这样不对,请教如何实现这一效果?
[此贴子已经被作者于2022/5/31 21:16:52编辑过]

--  作者:有点蓝
--  发布时间:2022/5/31 21:21:00
--  
Else 
    Dim pd As WinForm.TreeNode = e.Node.ParentNode
    If pd IsNot Nothing Then
dim bb as boolean = true
        For Each nd2 As WinForm.TreeNode In pd.Nodes
            if nd2.Checked = false then
bb=false
exit for
end if
        Next
        pd.Checked = bb 
    End If
End If

--  作者:采菊东篱下
--  发布时间:2022/5/31 22:02:00
--  
行了,谢谢,完整代码:
For Each nd1 As WinForm.TreeNode In e.Node.AllNodes \'清除子节点的选中标记
    nd1.Checked = e.Node.Checked
Next
Dim pd As WinForm.TreeNode = e.Node.ParentNode
If pd IsNot Nothing Then
    Dim bb As Boolean = True
    For Each nd2 As WinForm.TreeNode In pd.Nodes
        If nd2.Checked = False Then
            bb = False
            Exit For
        End If
    Next
    pd.Checked = bb 
End If
[此贴子已经被作者于2022/5/31 22:32:42编辑过]