借C版5楼代码加工了一下,在命令窗口测试基本可用,还不完善。不分级次,只要打勾了的就筛选(如一级勾选后,下面级次无论是否勾选,都对一级进行筛选)。实例见系统自带例子【目录树.table 自己加复选框】,如有狐友改进或更好的代码,恳请贴上来学习,谢谢!~
Dim tr As WinForm.TreeView
dim f0 as string
dim n1,n11,n10,n01,n222,n220,n202,n200,n002,n022,n020 as string
tr = Forms("主窗口").Controls("TreeView1")
for i as integer = 0 to tr.Nodes.count-1 '第一级的个数
Dim l1 As string = tr.Nodes(i).text
if tr.Nodes(i).checked then
n1 = n1 & "[产品] = " & "'" & l1 & "'" & "§"
n1 = n1.trim("§") & " or "
end if
for ii as integer = 0 to tr.Nodes(i).Nodes.count-1
Dim l11 As string = tr.Nodes(i).Nodes(ii).text
if tr.Nodes(i).checked and tr.Nodes(i).Nodes(ii).checked = true then
n11 = n11 & "[产品] = " & "'" & l1 & "'" & " and [客户] = " & "'" & l11 & "'" & "§"
n11 = n11.trim("§") & " or "
end if
if tr.Nodes(i).checked and tr.Nodes(i).Nodes(ii).checked = false then
n10 = n10 & "[产品] = " & "'" & l1 & "'" & " and [客户] <> " & "'" & l11 & "'" & "§"
n10 = n10.trim("§") & " or "
end if
if tr.Nodes(i).checked = false and tr.Nodes(i).Nodes(ii).checked = true then
n01 = n01 & "[产品] = " & "'" & l1 & "'" & " and [客户] = " & "'" & l11 & "'" & "§"
n01 = n01.trim("§") & " or "
end if
for iii as integer = 0 to tr.Nodes(i).Nodes(ii).Nodes.count-1
Dim l111 As string = tr.Nodes(i).Nodes(ii).Nodes(iii).text
if tr.Nodes(i).checked = true and tr.Nodes(i).Nodes(ii).checked = true and tr.Nodes(i).Nodes(ii).Nodes(iii).checked = true then
n222 = n222 & "[产品] = " & "'" & l1 & "'" & " and [客户] = " & "'" & l11 & "'" & " and [雇员] = " & "'" & l111 & "'" & "§"
n222 = n222.trim("§") & " or "
end if '===
if tr.Nodes(i).checked = true and tr.Nodes(i).Nodes(ii).checked = true and tr.Nodes(i).Nodes(ii).Nodes(iii).checked = false then
n220 = n220 & "[产品] = " & "'" & l1 & "'" & " and [客户] = " & "'" & l11 & "'" & " and [雇员] <> " & "'" & l111 & "'" & "§"
n220 = n220.trim("§") & " or "
end if '==0
if tr.Nodes(i).checked and tr.Nodes(i).Nodes(ii).checked = false and tr.Nodes(i).Nodes(ii).Nodes(iii).checked = true then
n202 = n202 & "[产品] = " & "'" & l1 & "'" & " and [客户] <> " & "'" & l11 & "'" & " and [雇员] = " & "'" & l111 & "'" & "§"
n202 = n202.trim("§") & " or "
end if '=0=
if tr.Nodes(i).checked = true and tr.Nodes(i).Nodes(ii).checked = false and tr.Nodes(i).Nodes(ii).Nodes(iii).checked = false then
n200 = n200 & "[产品] = " & "'" & l1 & "'" & " and [客户] <> " & "'" & l11 & "'" & " and [雇员] <> " & "'" & l111 & "'" & "§"
n200 = n200.trim("§") & " or "
end if '=00
if tr.Nodes(i).checked = false and tr.Nodes(i).Nodes(ii).checked = false and tr.Nodes(i).Nodes(ii).Nodes(iii).checked = true then
n002 = n002 & "[产品] = " & "'" & l1 & "'" & " and [客户] = " & "'" & l11 & "'" & " and [雇员] = " & "'" & l111 & "'" & "§"
n002 = n002.trim("§") & " or "
end if '===
if tr.Nodes(i).checked = false and tr.Nodes(i).Nodes(ii).checked = true and tr.Nodes(i).Nodes(ii).Nodes(iii).checked = false then
n020 = n020 & "[产品] = " & "'" & l1 & "'" & " and [客户] = " & "'" & l11 & "'" & " and [雇员] <> " & "'" & l111 & "'" & "§"
n020 = n020.trim("§") & " or "
end if '==0
if tr.Nodes(i).checked = false and tr.Nodes(i).Nodes(ii).checked = true and tr.Nodes(i).Nodes(ii).Nodes(iii).checked = true then
n022 = n022 & "[产品] = " & "'" & l1 & "'" & " and [客户] = " & "'" & l11 & "'" & " and [雇员] = " & "'" & l111 & "'" & "§"
n022 = n022.trim("§") & " or "
end if '===
next
next
next
f0 = n1 & n11 & n10 & n01 & n222 & n220 & n202 & n200 & n002 & n020 & n022
if len(f0) >=3 '其实大于空就行了.
f0 = left(f0,len(f0)-3)
Tables("订单").Filter = f0
else
Tables("订单").Filter = "产品 = '^_^'" '什么也不显示.
end if
[此贴子已经被作者于2010-3-10 18:19:59编辑过]