首先谢谢狐爹!!!
如何实现多选不同父节点下的子节点进行筛选
建立了一个窗口,插入目录树控件
窗口AfterLoad代码
Dim tr As WinForm.TreeView = e.Form.Controls("TreeView1")
tr.BuildTree("文件管理", "大类|二类|三类") ------- 为三级目录树
http://www.foxtable.com/help/index.html?n=2503.htm 此示例为两级
看了论坛里的 “[求助] 复选框目录树 增加节点 ”的主题,引用了代码:
Dim trv As WinForm.TreeView = e.Sender
Dim flt As String
For Each nd As WinForm.TreeNode In e.node.Nodes '同步子节点选中状态
nd.Checked = e.Node.Checked
Next
If e.node.ParentNode IsNot Nothing Then '去掉父节点选中状态
e.node.ParentNode.Checked = False
End If
For Each nd As WinForm.TreeNode In trv.AllNodes
If nd.Level > 0 AndAlso nd.ParentNode.Checked Then '如果父节点选中
Continue For '跳过此节点,处理下一结点
End If
If nd.Checked Then
If flt > "" Then
flt = flt & " Or " '注意用or而不是And
End If
If nd.Level = 0 Then '注意下面的条件都要用括号括起来
flt = flt & "(大类 = " & nd.Text & ")"
ElseIf nd.Level = 1 Then '注意下面的条件都要用括号括起来
flt = flt & "(大类 = " & nd.ParentNode.Text & " And 二类 = '" & nd.text & "')"
Else
flt = flt & "(大类 = " & nd.ParentNode.ParentNode.Text & " And 二类 = '" & nd.ParentNode.text & "' And 三类 = '" & nd.Text & "')"
End If
End If
Next
Tables("文件管理").Filter = flt
提示:System.Data.EvaluateException: 未找到列[软件]
改用狐神mr725的代码,如下:
Dim trv As WinForm.TreeView = e.Sender
Dim flt,a,b,c As String
For Each nd As WinForm.TreeNode In e.node.Nodes '同步子节点选中状态
nd.Checked = e.Node.Checked
Next
If e.node.ParentNode IsNot Nothing Then '去掉父节点选中状态
e.node.ParentNode.Checked = False
End If
Dim ndf As WinForm.TreeNode = trv.SelectedNode
If ndf IsNot Nothing Then
If ndf.Checked Then
If ndf.Level = 0 Then '注意下面的条件都要用括号括起来
a = ndf.Text
flt = " 大类 = '" & a & "'"
End If
If ndf.Level = 1 Then
a = ndf.ParentNode.text
b = ndf.Text
flt = "大类 = '" & a & "' And 二类 = '" & b & "'"
End If
If ndf.Level = 2 Then
Dim pth() As String = ndf.FullPath.Split("\")
a = pth(0)
b = pth(1)
c = ndf.Text
flt = "大类 = '" & a & "' And 二类 = '" & b & "' And 三类= '" & c & "'"
End If
End If
End If
Tables("文件管理").Filter = flt
(相同父节点下多选子节点,可以筛选,多选不同父节点下的子节点就不能进行筛选)
虽然不会报错,但是没有达到以下的效果:
多选不同父节点下的子节点进行筛选
用多选目录树的复选框对表进行筛选
比如当我点选编程下的开发项目,再点选软件下 手机软件的诺基亚复选框,会筛选出相应的行在表中
文字功底差,可能说的不够通顺,还请狐爹莫怪,谢谢
[此贴子已经被作者于2012-7-19 8:05:10编辑过]