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.
Printable View
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.
You don't have to clear and reload everything - if you know parent node then what's the problem with adding new child?
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.
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
Hi RhinoBull,
Thanks alot for the example. I just did this a few minutes ago.
It does what I want it to do now. Can you please verify that I am on the right track.:afrog:Code:Set nd = frmItemManager.trvTree.Nodes.Add("c" & TreeRel, tvwChild, "i" & LastId, Trim(txtNewItemTypeName.Text))
nd.ForeColor = &H400000
nd.Bold = True
nd.EnsureVisible
Syntax wise posted code looks fine - whether it does what you need it to do you are the one to verify.
Regards.