elmonko
elmonko

Reputation: 685

Treenode not appearing when program restarts

the below code is run from a double click event on a listbox that copies the selected file to the selected node directory on a treeview then adds the selected text as a child node.

It appears to work fine however when the program is closed and then re-opened its not showing the child node.

Any pointers........

    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

The below code is taken entirely from a doubleclick event of the 1st listbox

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

Upvotes: 0

Views: 86

Answers (1)

David Sdot
David Sdot

Reputation: 2333

Think that's want you 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

        ...

Upvotes: 1

Related Questions