以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  如何在两棵相同的树上定位选中的节点  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=40902)

--  作者:sunsenfeng
--  发布时间:2013/10/5 20:15:00
--  如何在两棵相同的树上定位选中的节点

请教老师

有两棵相同的目录树,在不同的窗口上,如何用其中一棵树上获得的节点的Fullpath,将所选节点还原在另一棵树上

 


--  作者:有点甜
--  发布时间:2013/10/5 20:30:00
--  
没有简单的方法,只能是遍历整棵树比较,再选中。
--  作者:sunsenfeng
--  发布时间:2013/10/5 20:45:00
--  

甜老师,能不能给个简单例子?

多谢


--  作者:逛逛
--  发布时间:2013/10/5 20:53:00
--  

没做过,但有个建议可以试试

 

 

点击第一棵树时,向上遍历每个节点的 Index 组成字符串变量 传递

 

第二棵树 接到后,分割变量,依次展开  Nodes(Index).Expand()

 

前提是两棵树完全一样。


--  作者:有点甜
--  发布时间:2013/10/5 20:54:00
--  
 参考代码

Dim fullPath As String = "ddd\\ddd\\ddd"
For Each nd As WinForm.TreeNode In tv.AllNodes
    If nd.FullPath = fullPath Then
        tv.SelectedNode = nd
        Exit For
    End If
Next

--  作者:sunsenfeng
--  发布时间:2013/10/5 21:12:00
--  

甜老师,伟大的创意

 


--  作者:程兴刚
--  发布时间:2013/10/5 21:21:00
--  

如果真的是两棵一模一样的树,那就好办了,假如改变目录树1的某节点复选框,目录树2跟着同步:

 

Dim tr As WinForm.TreeView = e.Form.Controls("TreeView2")
Dim nd As WinForm.TreeNode

Dim s As String = e.node.FullPath
Dim Values() As String
Values = s.split("\\")
For Index As Integer = 0 To Values.Length - 1
    If Index = 0
        nd = tr.Nodes(Values(Index))
    Else
        nd = nd.Nodes(Values(Index))
    End If
Next
nd.Checked = e.Node.Checked \'这就是您要的节点


--  作者:有点甜
--  发布时间:2013/10/5 21:38:00
--  

 呵呵,楼主,如7楼代码,一层一层往下找也行,更简单。
[此贴子已经被作者于2013-10-5 21:38:14编辑过]

--  作者:lsy
--  发布时间:2013/10/5 22:26:00
--  

窗口1中的目录树NodeMouseClick

If Forms("窗口2").Opened = False Then
    Forms("窗口2").Open()
End If
Dim tr As WinForm.TreeView = Forms("窗口2").Controls("TreeView1")
Dim nd As WinForm.TreeNode
For Each nd In tr.AllNodes
    If nd.DataRow("_Identify") = e.Node.DataRow("_Identify") AndAlso nd.Name = e.Node.Name AndAlso nd.Index = e.Node.Index Then
        tr.CollapseAll()
        nd.EnsureVisible()
        Exit For
    End If
Next


--  作者:sunsenfeng
--  发布时间:2013/10/5 22:27:00
--  
谢谢程老师,代码珍藏