Foxtable(狐表)用户栏目专家坐堂 → 能否根据目录树复选框的选中状态进行数据筛选?


  共有18317人关注过本帖树形打印复制链接

主题:能否根据目录树复选框的选中状态进行数据筛选?

帅哥哟,离线,有人找我吗?
mr725
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:MVP荣誉狐 帖子:5154 积分:31434 威望:0 精华:8 注册:2008/9/8 12:27:00
有条件的筛选合计,再线求高手教我,  发帖心情 Post By:2010/3/10 18:05:00 [显示全部帖子]

借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编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
mr725
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:MVP荣誉狐 帖子:5154 积分:31434 威望:0 精华:8 注册:2008/9/8 12:27:00
  发帖心情 Post By:2010/3/10 18:35:00 [显示全部帖子]

以下是引用czy在2010-3-10 18:29:00的发言:
呵呵,这种筛选应该用 In 好一点。
[此贴子已经被作者于2010-3-10 18:29:36编辑过]

从没有过,不知道如果表达,只能死板的套用学过的。 呵呵~


 回到顶部
帅哥哟,离线,有人找我吗?
mr725
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:MVP荣誉狐 帖子:5154 积分:31434 威望:0 精华:8 注册:2008/9/8 12:27:00
  发帖心情 Post By:2010/3/10 18:48:00 [显示全部帖子]

简化一下: 前面代码很多重复或多余了!~
Dim tr As WinForm.TreeView
dim f0 as string
dim n1,n11,n222 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).Nodes(ii).checked = true  then
            n11 = n11 & "[产品] = " & "'" & l1 & "'" & " and [客户] = " &  "'" & l11 & "'" & "§"
            n11 = n11.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).Nodes(ii).Nodes(iii).checked = true then
                n222 = n222 & "[产品] = " &  "'" & l1 & "'" & " and [客户] = " & "'" & l11 & "'" & _
                " and [雇员] = " & "'" & l111 & "'" & "§"
                n222 = n222.trim("§") &  " or "
            end if     '===
        next

    next

next
f0 = n1 & n11 & n222
if len(f0) >=3   '其实大于空就行了.
    f0 = left(f0,len(f0)-3)
    Tables("订单").Filter = f0
else
    Tables("订单").Filter = "产品 = '^_^'"   '什么也不显示.
end if
[此贴子已经被作者于2010-3-10 18:52:40编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
mr725
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:MVP荣誉狐 帖子:5154 积分:31434 威望:0 精华:8 注册:2008/9/8 12:27:00
  发帖心情 Post By:2010/3/10 20:21:00 [显示全部帖子]

C版这个会把第一级不同 第二或第三级相同的没有勾选的也筛选出来啊~

图片点击可在新窗口打开查看此主题相关图片如下:未命名0.jpg
图片点击可在新窗口打开查看

应该是这样的才对呀:


图片点击可在新窗口打开查看此主题相关图片如下:未命名01.jpg
图片点击可在新窗口打开查看
[此贴子已经被作者于2010-3-10 20:27:24编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
mr725
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:MVP荣誉狐 帖子:5154 积分:31434 威望:0 精华:8 注册:2008/9/8 12:27:00
  发帖心情 Post By:2010/3/10 21:19:00 [显示全部帖子]

不过楼主的意思没全懂,是只筛选最后一级的内容吗???

 回到顶部
帅哥哟,离线,有人找我吗?
mr725
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:MVP荣誉狐 帖子:5154 积分:31434 威望:0 精华:8 注册:2008/9/8 12:27:00
  发帖心情 Post By:2010/3/10 23:34:00 [显示全部帖子]

以下是引用liuruihua在2010-3-10 21:52:00的发言:

不一定,只要复选框打勾,都要筛选

这样的话,12楼代码基本可以了。看看是否符合你的要求?


 回到顶部
帅哥哟,离线,有人找我吗?
mr725
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:MVP荣誉狐 帖子:5154 积分:31434 威望:0 精华:8 注册:2008/9/8 12:27:00
  发帖心情 Post By:2010/3/11 10:36:00 [显示全部帖子]

以下是引用exonjee在2010-3-11 9:52:00的发言:

1、直接选择最后一级目录能否直接跟踪自动勾选到相应的根目录级
2、能否增加改变取消上级目录选定而自动取消下级目录勾选

你的问题与楼主的无关,论坛有类似问题的帖子,你可以搜索一下~ 


 回到顶部
帅哥哟,离线,有人找我吗?
mr725
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:MVP荣誉狐 帖子:5154 积分:31434 威望:0 精华:8 注册:2008/9/8 12:27:00
  发帖心情 Post By:2010/3/13 17:21:00 [显示全部帖子]

以下是引用老有所乐在2010-3-13 17:13:00的发言:
请问,12,13楼的代码用在何事件中

AfterCheckNode


 回到顶部