Results 1 to 7 of 7

Thread: Treeview Nodes - changing Node Names

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2008
    Location
    Texas
    Posts
    85

    Treeview Nodes - changing Node Names

    Anybody here work with Nodes is a TreeView?

    I have a tree structure and need to enable editing to the selected Node. I have a String Variable where the enduser can Type in a new Folder name, click ok and the structure gets made. But I need the Node Name to follow suit.

    The only way I know how to enable editing is:

    Code:
     ' Allow editing of the labels
                        TemplateTreeview.LabelEdit = True
    and re-walk to make the template.

    BUT - I have patient folders that need to be updated at the same time.

    Needs to work with this code using GoodFolderName as new Node Name:

    Code:
     Sub ChangeFolderName(ByVal BadLevel As String, ByVal GoodFolderName As String)
            'BadLevel is the entire path of the folder with the end being what will get adjusted...EU putsd in data after Prog
            ''''' i.e. PDF_Archives$\MedicalRecords\#####\MH Adult\MH Adult\SECTION 1 - IDENTIFYING INFORMATION AND CONSENTS\CR251 Diagnostic Form
            ''''' This is the folder that gets a new name - CR251 Diagnostic Form
            Dim CheckThis As String
            Dim info As New System.IO.DirectoryInfo(myRootpath)
            Dim subDir As DirectoryInfo
            Dim BadFolderName As String
            Dim ProgCheck As String
            Dim Flag As Integer = 0
    
            'Nod = TemplateTreeView.SelectedNode
            'NewNod = New TreeNode(GoodFolderName)
    
            ' Allow editing of the labels
            TemplateTreeView.LabelEdit = True
    
            MessageBox.Show("Make your changes and click OK")
    
            'Check to make sure folder exists in all instances (Chart Orders for program)
            'Delete pre-existing file
            If File.Exists("Outbox\2818\EMR_ChangeCheck.txt") Then
                File.Delete("Outbox\2818\EMR_ChangeCheck.txt")
            End If
    
            Using sw As StreamWriter = New StreamWriter("Outbox\2818\EMR_ChangeCheck.txt", True)
                For Each subDir In info.GetDirectories
                    PatientCB = subDir.ToString
    
                    'Program to check - WE ONLY CARE ABOUT CHANGING Structure if our Client is suppose to have that existing Chart order
                    ProgCheck = myRootpath + PatientCB + SecLevel + Prog                'file path to check
                    CheckThis = myRootpath + PatientCB + SecLevel + Prog + "\" + BadLevel
    
                    If Directory.Exists(ProgCheck) Then
                        ' set position to grab last folder name
                        'MessageBox.Show(CheckThis)
                        If Not Directory.Exists(CheckThis) Then
                            'Make file path new directory
                            'MessageBox.Show("1")
                            sw.WriteLine(PatientCB + " - Client doesn't have good Chart Order")
                        End If
                    End If
                Next
                'close SW
                sw.Close()
    
                'Grab file info of Errorlog... 0 means no data....2 in minimum empty file 
                Dim a As IO.FileInfo = New IO.FileInfo("Outbox\2818\EMR_ChangeCheck.txt")
                'MessageBox.Show(a.Length)
                If a.Length > 2 Then
                    Flag = 0
                    MessageBox.Show("You must correct the following before Folders in this structure can be deleted.  The Chart Order must be checked before proceeding.")
                    'Open notepad
                    System.Diagnostics.Process.Start("notepad.exe", "Outbox\2818\EMR_ChangeCheck.txt")
                    Exit Sub
                Else
                    Flag = 1
    
                End If
    
            End Using
            Flag = 1
            BadFolderName = BadLevel
            If Flag = 1 Then
                Dim Ans As Integer
                Ans = MessageBox.Show("Do you want to change " + BadFolderName + " to " + GoodFolderName + " in your Chart Order?", "Delete Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
                'If yes then delete folderIf Flag = 1 Then
                If Ans = vbYes Then
                    'Loop through the patients
    
                    For Each subDir In info.GetDirectories
                        PatientCB = subDir.ToString
                        'reset checkthis just to get rid of error
                        CheckThis = myRootpath + PatientCB + SecLevel + Prog + "\" + BadLevel
    
                        If Directory.Exists(CheckThis) Then
                            'MsgBox(CheckThis)
                            FileIO.FileSystem.RenameDirectory(CheckThis, GoodFolderName)
                        End If
                    Next
                    MessageBox.Show("All Folders in the Chart Order for " + Prog + " have been changed from " + BadFolderName + " to " + GoodFolderName + ".")
                Else
                    MessageBox.Show("You clicked no. The Folder - " + BadFolderName + " has NOT been renamed " + GoodFolderName + ".")
                    Exit Sub
                End If
            End If
    
    
        End Sub

  2. #2
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    351

    Re: Treeview Nodes - changing Node Names

    I think the Node Edition section of this article should help:
    http://www.functionx.com/vbnet/controls/treeview.htm

    Have not done it myself but it looks like there is a TreeNode.BeginEdit() which sounds like it does what you want.

    HTH
    Rico

    Using: VB.net & MS SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2008
    Location
    Texas
    Posts
    85

    Re: Treeview Nodes - changing Node Names

    Thanks - saw that article. Wasn't a match for the issue. Editting a made node outside the treeview is a lot different than opening the treeview to accept an edit.

  4. #4
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    351

    Re: Treeview Nodes - changing Node Names

    I don't understand what you mean by:
    Editting a made node outside the treeview is a lot different than opening the treeview to accept an edit.
    What does each mean, and which do you need to do
    Rico

    Using: VB.net & MS SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2008
    Location
    Texas
    Posts
    85

    Re: Treeview Nodes - changing Node Names

    You can open a tree to accept an edit where you type your edit into the tree directly and re-read the tree - write to your list.

    That is the easy way.

    Have a tree open and wanting that tree node to accept a new name based on a variable is the example I cannot find. That is indirectly editting the node.

  6. #6
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    351

    Re: Treeview Nodes - changing Node Names

    Unless I still don't quite understand, editing a node is simply TreeNode.Text = Variable

    But I assume you also need to find the right node to edit is that the case?

    If so this depends on what information you have. If the user has selected the node then: TreeView.SelectedNode

    if not and you just have the nodes name or id or something, then you can either loop through all available nodes or use TreeView.Nodes.Find()

    HTH
    Rico

    Using: VB.net & MS SQL

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2008
    Location
    Texas
    Posts
    85

    Re: Treeview Nodes - changing Node Names

    Thank you Rico - I was actually able to set it to selectednode.text = variable - I had to put a little string in the call above the function to retain a value.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width