以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- treeNode节点如何设置为父节点 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=170286) |
-- 作者:qq252476275 -- 发布时间:2021/7/20 17:41:00 -- treeNode节点如何设置为父节点 treeView控件 动态加载树节点 需要设置一些节点为父节点,一些为子节点 点击父节点时可以加载其下的子节点
|
-- 作者:qq252476275 -- 发布时间:2021/7/20 17:42:00 -- Dim ftp As new FTPClient Dim dls As List(of String) ftp.Host="192.168.66.218" ftp.Account = "ftpUser" ftp.Password = "123" dls = ftp.GetDirList("") Dim tree1 As WinForm.TreeView = e.Form.Controls("TreeView1") Dim nd As WinForm.TreeNode For Each dl As String In dls nd = tree1.Nodes.Add(dl) nd. Next dls = ftp.GetFileList("") For Each dl As String In dls tree1.Nodes.Add(dl) Next 这样加载的 1 (文件夹) 2 (文件夹) 1.xls 2.xls 效果 : +1 +2 1.xls 2.xls |
-- 作者:qq252476275 -- 发布时间:2021/7/20 18:55:00 -- 窗口afterShow事件 Dim labelPath As WinForm.Label = e.Form.Controls("Label4") labelPath.text = "" Dim ftp As new FTPClient Dim dls As List(of String) ftp.Host="192.168.66.218" ftp.Account = "ftpUser" ftp.Password = "123" dls = ftp.GetDirList("") Dim tree1 As WinForm.TreeView = e.Form.Controls("TreeView1") Dim nd As WinForm.TreeNode For Each dl As String In dls nd = tree1.Nodes.Add(dl,dl,"folder.ico") nd.Nodes.Add(dl,dl,"folder.icon") \' 额外增加一个子节点,显示父节点有了+号 Next dls = ftp.GetFileList("") For Each dl As String In dls tree1.Nodes.Add(dl,dl,"file.ico") Next 在treeView控件的BeforeExpandNode时间中 Dim nd As WinForm.TreeNode nd = e.Node nd.Nodes.Clear Dim strPath As String strPath = nd.FullName output.show(strPath) Dim ftp As new FTPClient Dim dls As List(of String) ftp.Host="192.168.66.218" ftp.Account = "ftpUser" ftp.Password = "123" dls = ftp.GetDirList(strPath) Dim tree1 As WinForm.TreeView = e.Form.Controls("TreeView1") Dim nd1 As WinForm.TreeNode For Each dl As String In dls nd1 = nd.Nodes.Add(dl,dl,"folder.ico") nd1.Nodes.Add(dl,dl,"folder.icon") Next dls = ftp.GetFileList(strPath) For Each dl As String In dls nd.Nodes.Add(dl,dl,"file.ico") Next 点击展开时,删除子节点,重新加载文件/文件夹, 遇到文件夹的继续额外增加子节点 |
-- 作者:qq252476275 -- 发布时间:2021/7/20 18:55:00 -- 不知是否有其他更简单的方法 |
-- 作者:有点蓝 -- 发布时间:2021/7/20 20:42:00 -- 只能这样 |