【发布时间】:2014-01-21 00:26:21
【问题描述】:
下面的代码是从列表框上的双击事件运行的,该事件将选定的文件复制到树视图上的选定节点目录,然后将选定的文本添加为子节点。
它似乎可以正常工作,但是当程序关闭然后重新打开时,它没有显示子节点。
任何指针............
Dim Copy2 = aMailbox & tvProgress.SelectedNode.Text & "\" & lstRequired.Text
Dim Copy1 = rPath & "\" & lstRequired.Text
If File.Exists(Copy2) Then
MsgBox("File already added. Please edit from the view above", MsgBoxStyle.OkOnly, "Lynx Control Panel")
Exit Sub
End If
If File.Exists(Copy1) Then
File.Copy(Copy1, Copy2)
tvProgress.SelectedNode.Nodes.Add(lstRequired.Text)
tvProgress.ExpandAll()
Else
MsgBox("This file no longer exists in your Lynx Repository. Please select another", MsgBoxStyle.OkOnly, "Lynx Control Panel")
Exit Sub
End If
以下代码完全取自第一个列表框的双击事件
Dim n As Integer
Dim i As Integer = lstPlanned.SelectedIndex
If lstPlanned.SelectedItems.Count = 0 Then Exit Sub
For n = 0 To UBound(AllDetails)
If AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps = lstPlanned.SelectedItem Then
If Not My.Computer.FileSystem.DirectoryExists(zMailbox & AllDetails(n).uFile) Then
MsgBox("No files located for " & vbNewLine & (AllDetails(n).uName & " (" & AllDetails(n).uCode) & ")" & vbNewLine & " " & vbNewLine & "Please try another...", MsgBoxStyle.OkOnly, "Lynx Control Panel")
Exit Sub
End If
System.IO.Directory.CreateDirectory(aMailbox & "\" & AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps)
For Each f In Directory.GetFiles(zMailbox & AllDetails(n).uFile, "*.dbf")
If File.Exists(f) Then
File.Copy(f, Path.Combine(aMailbox & "\" & AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps, Path.GetFileName(f)), True)
End If
Next
For Each f In Directory.GetFiles(zMailbox & AllDetails(n).uFile, "*.ini", SearchOption.AllDirectories)
If File.Exists(f) Then
File.Copy(f, Path.Combine(aMailbox & "\" & AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps, Path.GetFileName(f)), True)
End If
Next
For Each f In Directory.GetFiles(zMailbox & AllDetails(n).uFile, "*.txt", SearchOption.AllDirectories)
If File.Exists(f) Then
File.Copy(f, Path.Combine(aMailbox & "\" & AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps, Path.GetFileName(f)), True)
End If
Next
tvProgress.Nodes.Remove(rN)
tvProgress.Nodes.Insert(0, rN)
tvProgress.Nodes.Add(New TreeNode(AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps))
If i >= 0 And i < lstPlanned.Items.Count Then
lstPlanned.Items.RemoveAt(i)
End If
Exit Sub
End If
Next
【问题讨论】:
-
Node 是在运行时添加的,那么它应该如何在重启时出现?
-
我的父节点使用
DirectoryInfo方法在重启时返回,但是子节点是已复制到父目录中的文件,这些文件需要在重启时作为父节点返回 -
在你的程序中你从哪里开始填充树节点?新的,加载的...
-
在程序启动时创建一个新的树节点,并定义了一个根节点。从另一个列表框中双击项目并将其复制到创建父节点的树视图。使用副本创建目录并复制某些文件。然后我们回到最初的问题。基本上我需要运行像
DirectoryInfo这样的过程并使用目录中的文件填充相关的父节点 -
你能显示你填充 TreeNodeView 的部分吗?我会说,当您拥有每个文件夹的 DirectoryInfo 时,您可以使用 GetFiles 访问其中的文件并将其附加到添加的最后一个父节点。但也许我没听懂……