Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共7 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:[求助] 目录树展开与关闭

1楼
古奇 发表于:2011/11/14 9:42:00

当单击节点时,选定的节点展开,同层的其它节点关闭。。

 

Dim nd As WinForm.TreeNode = trv.SelectedNode
Dim id As Integer = nd.index
If e.Node.Level = 0 Then
    Dim cnt As Integer  = trv.Nodes.Count - 1
    For i As Integer = cnt To 0 Step -1
        If trv.Nodes.Count >= 0 Then
            If i=id
                trv.Nodes(i).Expand()
            Else
                trv.Nodes(i).Collapse()
            End If
        End If
    Next

ElseIf e.Node.Level = 1 Then
    Dim cnt As Integer  = trv.Nodes.Count - 1
    For i As Integer = cnt To 0 Step -1
        If trv.Nodes.Count >= 0 Then
            If i=id
                trv.Nodes(i).Nodes(i).Expand()
            Else
                trv.Nodes(i).Nodes(i).Collapse()
            End If
        End If
    Next

End If

 

这个只能做到根节点,往下的就出错了。。。

2楼
狐狸爸爸 发表于:2011/11/14 9:55:00

用这个比较好:
 
http://www.foxtable.com/help/topics/2302.htm


大概就是这样:
 
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
For Each nd As WinForm.TreeNode In trv.AllNodes
    If nd.Level = e.Node.Level AndAlso nd.FullPath <> e.Node.FullPath then
        trv.Nodes(i).Collapse()
    End If
Next
e.Node.Expand()

3楼
古奇 发表于:2011/11/14 11:06:00

图片点击可在新窗口打开查看。。。谢狐爸

4楼
古奇 发表于:2011/11/14 16:44:00

Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
If e.Node.Level = 0 Then
    Dim cnt As Integer  = trv.Nodes.Count - 1
    For i As Integer = cnt To 0 Step -1
        For Each nd As WinForm.TreeNode In trv.AllNodes
            If nd.Level = e.Node.Level AndAlso nd.FullPath <> e.Node.FullPath Then
                trv.Nodes(i).CollapseAll()
            Else
                e.Node.Expand()
            End If
        Next
    Next
ElseIf e.Node.Level = 1 Then
    Dim cnt As Integer  = trv.SelectedNode.ParentNode.Nodes.Count - 1
    For i As Integer = cnt To 0 Step -1
        For Each nd As WinForm.TreeNode In trv.AllNodes
            If nd.Level = e.Node.Level AndAlso nd.FullPath <> e.Node.FullPath Then
                trv.Nodes(Value(0)).Nodes(i).CollapseAll()
            Else
                e.Node.Expand()
            End If
        Next
    Next
ElseIf e.Node.Level = 2 Then
    Dim cnt As Integer  = trv.SelectedNode.ParentNode.Nodes.Count - 1
    For i As Integer = cnt To 0 Step -1
        For Each nd As WinForm.TreeNode In trv.AllNodes
            If nd.Level = e.Node.Level AndAlso nd.FullPath <> e.Node.FullPath Then
                trv.Nodes(Value(0)).Nodes(Value(1)).Nodes(i).CollapseAll()
            Else
                e.Node.Expand()
            End If
        Next
    Next
ElseIf e.Node.Level = 3 Then
    Dim cnt As Integer  = trv.SelectedNode.ParentNode.Nodes.Count - 1
    For i As Integer = cnt To 0 Step -1
        For Each nd As WinForm.TreeNode In trv.AllNodes
            If nd.Level = e.Node.Level AndAlso nd.FullPath <> e.Node.FullPath Then
                trv.Nodes(Value(0)).Nodes(Value(1)).Nodes(Value(2)).Nodes(i).CollapseAll()
            Else
                e.Node.Expand()
            End If
        Next
    Next
End If

 

可不可以简化代码   不管目录树的层数。。。?

5楼
狐狸爸爸 发表于:2011/11/14 16:48:00
先告诉我,你的设计任务是什么?
6楼
古奇 发表于:2011/11/14 16:52:00
仓库目录树。。有的商品规格分类层比较多,有的层比较少,我想单击是展开,双击就选定。。。
7楼
狐狸爸爸 发表于:2011/11/14 16:54:00

单击展开,这样不就行了吗:

 

e.Node.Expand()

共7 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .04297 s, 2 queries.