Deleting a node from TreeView

G

Guest

I would like to delete a node from treeview. I can add, I can rename, but I
don't see a delete method. The work around I've tried is to delete the
record from the table, clear treeview, then repopulate the tree. However,
after doing that my tree is collapsed. Is there a better way to do a delete?

Thanks,
Leif
 
R

Rob Parker

AFAIK, there is no delete method for nodes in a treeview control. Your
approach - repopulate the tree - is the only way to do it.

What you can do, though, is to set the expanded property of each node as you
add it. This allows you to open the tree in any state you want it. If you
want/need to open it in its previous state (an unknown mix of true/false
values for each node's expanded property), you'll need to add a field to the
table that the tree is based on, store the appropriate value in it when you
are processing node clicks, and use that in the recordset when you
re-populate the treee to restore its previous state.

HTH,

Rob

BTW, if you can tell me why I keep getting Run-Time Error -2147417848
"Automation error. The object invoked has disconnected from its clients@@"
in a treeview control I'd be eternally grateful! I've used treeview
controls in a couple of databases with no problems, but in another one I get
this error with monotonous regularity - and it usually crashes the whole
application!
 
G

Guest

Rob,

Thanks for your reply. I was afraid of that. I probably could use an array
to store the states, but I'm not sure its worth the effort. I see what the
client thinks.

On your problem, I goggled it and came up with the following. Hope it helps.

Receive an Error Like "The object invoked has disconnected from its clients"
and Must Re-Start the Application in Order to Perform Certain Activities
Issue:

A rare/intermittent issue has been observed when using ReliaSoft's software
products on Windows 2000 and some Windows NT systems with 2000 libraries. An
error like "The object invoked has disconnected from its clients" appears and
the user is unable to perform functions associated with the object
disconnect. The problem is resolved by re-starting the application.

Solution:

This problem is due to an issue with Windows 2000, not ReliaSoft software,
as confirmed by Microsoft. Microsoft's support document number Q293631
describes the issue. Microsoft has made a hot fix available and has announced
plans to address this issue with a service pack.
 
R

Rob Parker

Leif,

Thanks for the feedback on my problem. My previous Googling had found a few
(and I mean few, not hundreds) similar problems/suggestions, related to
various third-party programs; and also a very few with treeview controls in
Access. Unfortunately, some had anything at all useful in suggesting how I
can fix my problem; which isn't caused by anything other than the
combination of Access (2000) and mscomctl.ocx.

I'm still playing (I use that term advisedly - it's actually a real
pain-in-the-bum) with a test database (the real problem one is at work) to
try to reproduce my problem, but with no luck to date.

Rob

<snip>
 
J

jeff

First - I find it pretty surprising what you guys are saying about
the standard TreeView. I haven't tried standard MS Treeview
within Access, but in VB you can just write
TreeView1.Nodes.Remove 2
to remove the 2nd node in the tree.

If this doesn't work in Access, then as it sounds like you are open
to other 3rd party Tree controls, definitely you should take a look
a look at our TList 7 control. Of course you can remove nodes
from TList in Access and it is much much faster and more flexible
than MS Treeview as well. In case you already have lots of
MS Treeview syntax we also provide a syntax compatible
wrapper ( TLTreeview ) with TList. ( however using TList directly
without the wrapper gives much better performance )

You can download TList for evaluation from our web site at
www.Bennet-Tec.com Also check out the compatibility
page on our web site for key information about use of TList
within Access


If you are interested I'll be happy to answer questions
on TList for you. I think there are also a few TList users
here in the newsgroup.

* * Please include a copy of this message with your reply

Jeff Bennett
Jeff @ Bennet-Tec.Com

* Bennet-Tec Information Systems, Inc
* 50 Jericho Tpk, Jericho, NY 11753
* Phone 516 997 5596, Fax - 5597
* RELIABLE Components Make You Look Sharp!
* TList/Pro * ALLText HT/Pro * MetaDraw *
* Custom Software Development Services Too.
* WWW.Bennet-Tec.Com

=================== ===================
 
R

Rob Parker

Thanks for the comment, Jeff.

My previous use of treeview controls (I'm using the one from MS Windows
Common Controls V6 (Sp6) ActiveX library) hadn't really made me need to
look at them in serious detail, but in the last week my current work has got
me really down and dirty with them. And you're right - they do support the
Remove method - and the tree auto-updates if the node removed has nodes
below it. I do need appropriate code to keep the treeview and its
underlying data together, as they are not bound to their data - so if I
delete a node with the remove method, I also need to programmatically remove
the relevant record(s) from the underlying data table(s).

Rob
 
G

Guest

I tried the remove and it works great. Thanks for the help. It seems proper
documentation for treeview is lacking, or perhaps I just don't know where to
look. I'm using comctl1.hlp, and it makes no mention of a remove method that
I can find. Could you direct me to a better source of help for this control?

Thanks,
Leif
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top