2014-01-20 11 views
0

以下代碼是從列表框上的雙擊事件運行的,該列表框將所選文件複製到樹狀視圖上的選定節點目錄,然後將選定文本添加爲​​子節點。Treenode在程序重新啓動時沒有出現

然而,當程序關閉然後重新打開它沒有顯示子節點時,它似乎工作正常。

任何指針........

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 
+0

節點是在運行時添加的,所以在重新啓動時它應該如何存在? –

+0

我有父節點使用'DirectoryInfo'方法重新啓動時返回,但是子節點是已被複制到父目錄中的文件,並且這些父節點需要在父母重新啓動時返回 – elmonko

+0

在程序中的哪個位置開始填充treenode ?新建,加載... –

回答

1

認爲這是要你want..maybe ;)

 ... 

     System.IO.Directory.CreateDirectory(aMailbox & "\" & AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps) 

     ' After the Dir is created Node is added to the TreeView 
     tvProgress.Nodes.Remove(rN) 
     tvProgress.Nodes.Insert(0, rN) 
     tvProgress.Nodes.Add(New TreeNode(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) 

       'As ParentNode already exists as Pos 0 you can add child nodes to it 
       tvProgress.Nodes(0).Nodes.Add(Path.GetFileName(f)) 

      End If 
     Next 

     ... 
相關問題