Rss & SiteMap
Foxtable(狐表) http://www.foxtable.com
这个问题有点大了,Nodes是根据目录树的层数级增加的,我不知道动态遍历n层目录树的代码应该怎么写,这是一个难点。
另外如果象上图所示,勾选了pd03再直接跳开Cs01而选择下一层,要动态组合成筛选语句估计这也是个难点。
如果层级固定,还是好办的,否则要定义函数,使用递归。
楼主提出的的目录树复选框筛选数据很实用,
老大代码怎样实现?请贴个示例
如果层级固定,还是好办的,否则要定义函数,使用递归。
嗯,固定层级能实现,不过代码好象比较烦琐,这是我写的遍历三层的测试代码(中间还未判断哪些层级重复,哪些层级缺失)
For i As integer = 0 to tv.Nodes.Count -1
if tv.Nodes(i).Checked Then
tvname = tvname & ",'" & tv.Nodes(i).name & "'"
End If
For n As integer = 0 to tv.Nodes(i).Nodes.Count -1
if tv.Nodes(i).Nodes(n).Checked Then
tvname1 = tvname1 & ",'" & tv.Nodes(i).Nodes(n).name & "'"
End If
For x As integer = 0 to tv.Nodes(i).Nodes(n).Nodes.Count -1
if tv.Nodes(i).Nodes(n).Nodes(x).Checked Then
tvname2 = tvname2 & ",'" & tv.Nodes(i).Nodes(n).Nodes(x).name & "'"
End If
Next
Next
Next
借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