Results 1 to 6 of 6

Thread: [RESOLVED] How can I refresh a treeview with new nodes without clearing then reloading the tree

  1. #1

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Resolved [RESOLVED] How can I refresh a treeview with new nodes without clearing then reloading the tree

    Hi Guys,

    How can I do the above. When I add new nodes to my treeview I call the original LoadTree Sub to clear then reload the tree. How can I refresh it without doing that as it is very time consuming to have to reopen sub categories in the tree.

  2. #2

  3. #3

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How can I refresh a treeview with new nodes without clearing then reloading the tree

    Hi Guys,

    Could someone please drop me an example. I add a new node to the tree but how do I get the new node to be visible immediately. Currently, I add a node then call a sub to reload the tree which involves clearing all the nodes and then loading them from a table in my database.

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: How can I refresh a treeview with new nodes without clearing then reloading the tree

    I hope you'll figure it out how to apply this quick sample to your aplication:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
        With TreeView1
            .Style = tvwTreelinesPlusMinusText
            .Nodes.Add , , "root", "Root"
            .Nodes.Add "root", tvwChild, "parent1", "Parent 1"
            .Nodes.Add "parent1", tvwChild, "child1", "Child 1"
            .Nodes.Add "parent1", tvwChild, "child2", "Child 2"
            .Nodes("root").Expanded = True
        End With
        Command1.Caption = "Add New Child Node"
    End Sub
    
    Private Sub Command1_Click()
        AddNewChildNode TreeView1, "parent1", "child" & TreeView1.Nodes.Count + 1, "Child " & TreeView1.Nodes("parent1").Children + 1
    End Sub
    
    Public Sub AddNewChildNode(tv As TreeView, parentnode As String, nodekey As String, nodetext As String)
        With tv
            .Nodes.Add parentnode, tvwChild, nodekey, nodetext
            .Nodes(parentnode).Expanded = True
        End With
    End Sub

  5. #5

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How can I refresh a treeview with new nodes without clearing then reloading the tree

    Hi RhinoBull,

    Thanks alot for the example. I just did this a few minutes ago.

    Code:
    Set nd = frmItemManager.trvTree.Nodes.Add("c" & TreeRel, tvwChild, "i" & LastId, Trim(txtNewItemTypeName.Text))
        nd.ForeColor = &H400000
        nd.Bold = True
        nd.EnsureVisible
    It does what I want it to do now. Can you please verify that I am on the right track.

  6. #6

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