Results 1 to 7 of 7

Thread: [RESOLVED] Add child nodes to an existing treeview

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260

    Resolved [RESOLVED] Add child nodes to an existing treeview

    My application presents a set navigational treeview on startup of the project. I allow the user to search for records using 1 of several child nore methods.

    Now when they come back from that search a will need to add 1 or more additional child nodes

    Example

    Patient Selection

    by Unit

    by Next Review Date

    Individual Patient

    Consultant Note(s)



    When user returns from say the individual Patient search I nees to load 1 or more child nodes under the Consultant Note(s) node

    Patient Selection

    by Unit

    by Next Review Date

    Individual Patient

    Consultant Note(s)

    Patient record 1

    Patient record 2


    Here is what I have (new at this control)

    //adding the upper level node to the tree

    treeViewProgressNotes.BeginUpdate()



    // prevent repaint while adding nodes



    aNode = treeViewProgressNotes.Nodes.Add("Patient Selection")

    // then this will add a child at the next level

    bNode = anode.Nodes.Add("by Unit")

    bNode.Tag = 'Select by Unit, then Patient'

    cNode = bnode.Nodes.Add("by Admission Date (multiple)")

    cNode = bnode.Nodes.Add("by Next Review Date (multiple)")

    cNode = bnode.Nodes.Add("Individual Patient")

    cNode.Tag = 'Select by Unit, then Patient'

    bNode = anode.Nodes.Add("by MedRec or Search")

    bNode.Tag = 'Select by MR#, or do a Patient Search by Name'

    bNode = anode.Nodes.Add("QuickSearch: Last 10 MR#'s Used")

    bNode.Tag = 'Select from a list of up to last 10 patients accessed'

    //adding 4 more upper level nodes at the tree root level

    aNode = treeViewProgressNotes.Nodes.Add("Consultant Note(s)")



    I want to ADD THEM HERE

    Patient record 1

    Patient record 2


    How do I set the reference to this node (treeViewProgressNotes.Nodes.Add("Consultant Note(s)")
    ) in order to add some children??

    Thanks

    gollnick
    William E Gollnick

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Add child nodes to an existing treeview

    How do I set the reference to this node (treeViewProgressNotes.Nodes.Add("Consultant Note(s)")
    ) in order to add some children??
    You already did something similar, try this
    Code:
    aNode = treeViewProgressNotes.Nodes.Add("Consultant Note(s)")
    aNode.Nodes.Add("Patient record 1")
    aNode.Nodes.Add("Patient record 2")



  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Add child nodes to an existing treeview

    you mean you want to search for a node, then add 2 child nodes to the found node?

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260

    Re: Add child nodes to an existing treeview

    [QUOTE=.paul.;4492699]you mean you want to search for a node, then add 2 child nodes to the found node?[/poll]I

    YesYes
    William E Gollnick

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Add child nodes to an existing treeview

    I don't understand your program logic.
    It appears selecting or deselecting nodes should result in a node search by your predetermined criteria, but I don't see where you're giving the information of what to search for...

  6. #6
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Add child nodes to an existing treeview

    When you build the tree give each node a unique name, so you can find it using treeViewProgressNotes.Nodes.Find
    Code:
    Option Strict On
    Option Explicit On
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            Dim aNode As TreeNode
            Dim bNode As TreeNode
            Dim cNode As TreeNode
    
    
            '//adding the upper level node to the tree
    
            treeViewProgressNotes.BeginUpdate()
    
    
    
            '// prevent repaint while adding nodes
    
    
    
            aNode = treeViewProgressNotes.Nodes.Add("Patient Selection")
    
            '// then this will add a child at the next level
    
            bNode = aNode.Nodes.Add("by Unit")
    
            bNode.Tag = "Select by Unit, then Patient"
    
            cNode = bNode.Nodes.Add("by Admission Date (multiple)")
    
            cNode = bNode.Nodes.Add("by Next Review Date (multiple)")
    
            cNode = bNode.Nodes.Add("Individual Patient")
    
            cNode.Tag = "Select by Unit, then Patient"
    
            bNode = aNode.Nodes.Add("by MedRec or Search")
    
            bNode.Tag = "Select by MR#, or do a Patient Search by Name"
    
            bNode = aNode.Nodes.Add("QuickSearch: Last 10 MR#'s Used")
    
            bNode.Tag = "Select from a list of up to last 10 patients accessed"
    
            '//adding 4 more upper level nodes at the tree root level
    
            aNode = treeViewProgressNotes.Nodes.Add("Consultant Note(s)")
            aNode.Name = "cn" 'GIVE THIS NODE A NAME SO WE CAN FIND IT.
        End Sub
    
        Private Function FindNode(strName As String) As TreeNode
    
            Dim n() As TreeNode = treeViewProgressNotes.Nodes.Find(strName, True)
    
            If n.Length > 0 Then
                Return n(0)
            Else
                Return Nothing
            End If
    
        End Function
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim nd As TreeNode = FindNode("cn")
            If nd Is Nothing Then
                MessageBox.Show("Cannot find")
            Else
                nd.Nodes.Add("child 1")
                nd.Nodes.Add("child 2")
            End If
        End Sub
    End Class



  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [RESOLVED] Add child nodes to an existing treeview

    @4x2y...

    good opportunity to use LINQ there:

    Code:
    Private Function FindNode(ByVal strName As String) As TreeNode
        Return treeViewProgressNotes.Nodes.Find(strName, True).FirstOrDefault
    End Function

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