Foxtable(狐表)用户栏目专家坐堂 → treeNode节点如何设置为父节点


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

主题:treeNode节点如何设置为父节点

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


加好友 发短信
等级:幼狐 帖子:196 积分:1429 威望:0 精华:0 注册:2020/5/23 14:56:00
treeNode节点如何设置为父节点  发帖心情 Post By:2021/7/20 17:41:00 [显示全部帖子]

treeView控件 动态加载树节点

需要设置一些节点为父节点,一些为子节点

点击父节点时可以加载其下的子节点

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


加好友 发短信
等级:幼狐 帖子:196 积分:1429 威望:0 精华:0 注册:2020/5/23 14:56:00
  发帖心情 Post By: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
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:196 积分:1429 威望:0 精华:0 注册:2020/5/23 14:56:00
  发帖心情 Post By: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
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:196 积分:1429 威望:0 精华:0 注册:2020/5/23 14:56:00
  发帖心情 Post By:2021/7/20 18:55:00 [显示全部帖子]

不知是否有其他更简单的方法

 回到顶部