Dim sz As New List(Of Integer) Dim trv As WinForm.TreeView = e.form.controls(TreeView1) For Each nd As WinForm.TreeNode In trv.AllNodes If nd.IsExpanded = True SZ.Add(nd.Index) End If Next
'''变更目录树后,重生成的代码
For Each nd1 As WinForm.TreeNode In trv.AllNodes If sz.Contains(nd1.Index) nd1.Expand End If Next
顺便再转享下天老师的目录树只展开一个节点的代码 If e.Node.Level = 0 Then For Each pg As WinForm.TreeNode In e.Sender.Nodes If pg.Name <> e.Node.Name Then pg.CollapseAll() End If Next Else For Each pg As WinForm.TreeNode In e.Node.ParentNode.Nodes If pg.Name <> e.Node.Name Then pg.CollapseAll() End If Next End If