Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear / Delete Nodes from TreeView Control 2

Status
Not open for further replies.

JimFlower

Programmer
Jun 21, 2001
42
0
0
GB
I have a treeView control which I have populated with Nodes but I can't figure out how to reinitilise it to add another set of nodes

sofar I can add nodes other code examples are welcome
ie
edit / update existing nodes
delete nodes
current node value referencing(im using the nodeclick event which has the selected Node passed to it)

 
Hi Jim,

Isn't working with the TreeView fun? :)

In any case, to clear the entire tree, just call the .Clear method of the .Nodes collection:
Code:
tvMyTree.Nodes.Clear
As for the other items, the treeview control uses a string key identifier for each node which is set as you add each node to the tree:
Code:
tvMyTree.Nodes.Add(Key:= "n101", Text:= "My Node Title")
So in order to change the node properties, you need to reference the node by it's Key identifier:
Code:
tvMyTree.Nodes("n101").Text = "My New Node Title"
tvMyTree.Nodes.Remove "n101"
etc...

For a good reference of the TreeView methods and properties, check out the articles on MSDN:


Hope this helps.

- Glen

Know thy data.
 
Jim,

Thanks for the help with the References - I am not familiar with the P&D wizard.

I use the following code to clear the nodes:

ActiveXCtl0.Nodes.Clear

And I use the following to respond to nodeclicks:

Private Sub Activexctl0_nodeclick(ByVal node As Object)
Dim selnode As node
Dim nodetype As String

Set SoharDB = CurrentDb

Set selnode = node
reclen = Len(selnode.Key)
nodetype = Mid(selnode.Key, 1, 4)

iscontract = 0

Select Case nodetype
Case "Root"
Label11.Caption = Mid(selnode.Key, 5, reclen)
Child3.SourceObject = "AreaList"
Case "OBRT"
Label11.Caption = Mid(selnode.Key, 5, reclen)
Child3.SourceObject = "PersonListOA"
end select
end sub

The reason for the mid command is that I name my nodes with eight digit names - the first four digits tell me what type of node it is so I can deploy the right sub-form and the second four I use to provide data to use in a query to filter the information displayed in the form.

Hope this helps.

Regards,
John
 
Hi John,

I have a similar setup to what you're doing in a KB app that I developed. I use a key such as "T1:N101" to identify which tree (root) and node id to reference, which is helpful since the application can reference several data sources in a single view. To identify the node type, I use the .Tag property of the Node object. This makes it easy to be more descriptive with regard to node object types, such as "Tree"; "Folder"; "Workgroup"; etc... The .Tag property is not used by any of the treeview's properties or methods systematically, so it's a good place to store custom information.

Hope this helps.

- Glen

Know thy data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top