可能是我表达的不清楚,其实我是想实现下面的功能,
此主题相关图片如下:360截图20121124-002.jpg

当我取消勾选左边目录树的"供应商"时能同步取消右边目录树中的相同表的供应商列
反过来如果勾选右边目录树的“录入”时能同步勾选左边目录树的“录入”
但奇怪的是有时可以,有时又不可以,原因就是1楼我描述的,如果每次先选中复选框右边的节点文本再勾选复选框就没问题。如果直接去勾选复选框就出现不确定的情况。
所以关键就是在勾选或取消勾选前能先选中要操作的这个节点就可以了,但不知道你说的那句代码要怎么加,加在哪里?
我在目录树2的AfterCheckNode中已用了下面的代码:
Dim tr1 As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim tr2 As WinForm.TreeView = e.Form.Controls("TreeView2")
Dim tr3 As WinForm.TreeView = e.Form.Controls("TreeView3")
Dim tr_Flow As WinForm.TreeView = e.Form.Controls("tr_Flow")
Dim nd1 As WinForm.TreeNode = tr1.SelectedNode
Dim nd2 As WinForm.TreeNode = tr2.SelectedNode
'Dim nd3 As WinForm.TreeNode = tr3.SelectedNode
Dim dr As DataRow
'同步子节点选中状态.
For Each nd As WinForm.TreeNode In e.Node.AllNodes
nd.Checked = e.Node.Checked
Next
'去掉父节点选中状态
If e.node.ParentNode IsNot Nothing Then
e.node.ParentNode.Checked = False
End If
If tr2.Focused AndAlso nd1 IsNot Nothing Then '一定要判断焦点是否在此目录树
'获取当前目录树所选节点的父节点(表名)
Dim tbn As String
Dim nds As WinForm.TreeNode
If nd2.level = 1 Then
tbn = nd2.ParentNode.Name
nds = nd2.ParentNode
Else
tbn = nd2.Name
nds = nd2
End If
'集合当前目录树下的顶级子节点下所有选中的值(排除顶级节点)
Dim nms As String
For Each nd As WinForm.TreeNode In nds.AllNodes
If nd.Checked And nd.level = 1 Then
nms = nms & "\" & nd.Name
End If
Next
'查找授权表中部门及角色及表名符合条件的行,如果找到则更新表中相应列的值
If nd1.Level = 0 Then
dr = DataTables("授权表").Find("部门 = '" & nd1.Name & "' And 角色 Is Null And 表名 = '" & tbn & "'")
Else
dr = DataTables("授权表").Find("部门 = '" & nd1.ParentNode.Name & "' And 角色 = '" & nd1.Name & "' And 表名 = '" & tbn & "'")
End If
If dr IsNot Nothing Then
If nms > "" Then
dr("可查看列") = nms.Trim("\")
'当可查看列的列名取消勾选时取消对应的可编辑列的复选框及更新授权表中对应的列值.
For Each nd As WinForm.TreeNode In tr3.AllNodes
If nd.Level =1 AndAlso nd2.level = 1 AndAlso nd.parentNode.Name = tbn AndAlso nd2.Name = nd.Name Then
If nms.Contains(nd.name) = False Then
nd.Checked = False
dr("可编辑列") = dr("可编辑列").Replace(nd.Name,"")
End If
End If
Next
Else '如果没有勾选,清空表中对应列的所有值
dr("可查看列") = Nothing
dr("可编辑列") = Nothing
dr("可操作流程") = Nothing
'将其他目录树中对应的节点的复选框清空.
For Each nd0 As WinForm.TreeNode In tr3.Nodes
If nd0.Name = tbn Then
nd0.Checked = False
For Each nd As WinForm.TreeNode In nd0.Nodes
nd.Checked = False
Next
End If
Next
End If
Else
'如果行不存在则新增行
代码略
End If
End If
[此贴子已经被作者于2012-11-24 14:21:08编辑过]