以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  目录树afterchecknode  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=123684)

--  作者:susu312
--  发布时间:2018/8/21 10:41:00
--  目录树afterchecknode

 

 

\'\'目录树生成代码
Tables("organList").Filter = ""
Dim tr As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim nd As WinForm.TreeNode
Dim dt As DataTable = DataTables("organList")
tr.StopRedraw()\'\'停止绘制目录树
tr.Nodes.Clear
\'tr.Nodes.Add("全部")
For Each dr As DataRow In dt.datarows
    If dr.IsNull("superName") Then
   \'If dr("organName") = _UserOrgan Then
        nd = tr.Nodes.Add(dr("organName"),dr("organName"))
        Functions.Execute("AddChildren",nd,dt)
    End If
Next
tr.ResumeRedraw() \'\'恢复绘制目录树

 

\'\'目录树checknode代码

Dim nms As String() = {"superName","organName"} \'指定生成目录树的各列
Dim qts As String() = {"\'","\'"} \'指定将各列的值括起来的符号,这里都是字符型,所以都是单引号
Dim trv As WinForm.TreeView = e.Sender
Dim flt As String
Dim nd As WinForm.TreeNode
For Each nd In e.node.allNodes \'清除子节点的选中标记
    nd.Checked = False
Next
nd = e.Node.ParentNode
Do While nd IsNot Nothing \'清除父节点的选中标记
    nd.Checked = False
    nd = nd.ParentNode
Loop
For Each nd In trv.AllNodes
    If nd.Checked  Then
        Dim rts() As String = nd.FullPath.Split("\\")
        Dim val As String = ""
        For i As Integer = 0 To rts.length - 1
            If val > "" Then
                val = val & " And "
            End If
            val = val & nms(i) & " = " & qts(i) & rts(i) & qts(i)
        Next
        If flt > "" Then
            flt = flt & " Or (" & val & ")"
        Else
            flt = val
        End If
    End If
Next
Tables("organList").Filter  = flt

 

 老师,您看这个目录树筛选只能是两级,如果我点县支行,它就报错了,我不会改afterchecknode代码,如何让它可以三级都筛选,也没有问题.


图片点击可在新窗口打开查看此主题相关图片如下:1.png
图片点击可在新窗口打开查看

--  作者:有点蓝
--  发布时间:2018/8/21 11:05:00
--  
……
Dim nms As String() = {"superName","organName","第三级列名"}
……

val = val & nms(i) & " = \'"  & rts(i) & "\'"

--  作者:susu312
--  发布时间:2018/8/21 11:12:00
--  
以下是引用有点蓝在2018/8/21 11:05:00的发言:
……
Dim nms As String() = {"superName","organName","第三级列名"}
……

val = val & nms(i) & " = \'"  & rts(i) & "\'"

老师,您看我那个目录树其实是根据递归生成的,单位之前互为上下级,


--  作者:有点蓝
--  发布时间:2018/8/21 11:41:00
--  
For i As Integer = 0 To rts.length - 1
    If val > "" Then
        val = val & " or "
    End If
    val = val  & " organName = \'"  & rts(i) & "\'"
Next

--  作者:susu312
--  发布时间:2018/8/21 13:23:00
--  
以下是引用有点蓝在2018/8/21 11:41:00的发言:
For i As Integer = 0 To rts.length - 1
    If val > "" Then
        val = val & " or "
    End If
    val = val  & " organName = \'"  & rts(i) & "\'"
Next

 

老师,我是这么改的,但是现在,我比如把本级单位选中,它会把表里面的上级单位也选出来

 

 


图片点击可在新窗口打开查看此主题相关图片如下:1.png
图片点击可在新窗口打开查看

我试着改代码,但是没改对,


--  作者:有点蓝
--  发布时间:2018/8/21 14:04:00
--  
完整代码呢
--  作者:有点蓝
--  发布时间:2018/8/21 14:06:00
--  
For Each nd In trv.AllNodes
    If nd.Checked  Then
        If val > "" Then
            val = val & " or "
        End If
        val = val  & " organName = \'"  & nd.text & "\'"
    End If
Next