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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing a Treeview Control

Status
Not open for further replies.

Frink

Programmer
Mar 16, 2001
798
GB
Hallo,

I have a treeview control which I populate from a table, each record is a node. I use "N" & PrimaryKeyField (which is an Autonumber) as the Key for each node.
My problem is how to clear the tree to repopulate it?
I currently use Me!ActiveXCtl0.Nodes.Clear to clear the TreeView control, but when I re-run my populate code, it gives the following error:
35602 Key is not unique in collection
Suggesting that it is trying to add the same key again, although I thought they had all been deleted.
If I close the form and re-open it it populates correctly.

Any ideas?

- Frink
 
try .remove I also find that it works a lot faster if I do it from the reverse

Private sub Clearnodes
dim nodecount as long
with treeview1.nodes
for nodecount = .count to 1 step -1
.remove nodecount
next
end with
end sub
 
I find it easiest to create an array of nodes from the data (in my case an interface table showing child parent relationships) and then add those nodes to the treeview nodes collection at run time JHall
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top