Solved

VB.Net How to completely clear a TreeView

Posted on 2010-09-10
5
543 Views
Last Modified: 2013-11-27
I need to completely clear a TreeView control ready to accept new nodes. I have tried a couple of solutions from the net but still end up with the new nodes being appended to the bottom of the existing.

tvwPreAlert.Nodes.Clear() just does not do the job.
0
Comment
Question by:TeDeSm
5 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 33645285
1. Have you programmatically looked at treeview.Nodes.Count to make sure there are now 0?

2. Did you call treeview.BeginUpdate() before calling treeview.Nodes.Clear()? If so, are you calling treeview.EndUpdate() afterwards?

3. How do you fill the treeview ? Is it through databinding ? If so, is your souce cleared ?
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33645327
try this ....
Private Sub TreeViewClear()
Dim x As Integer
With TreeView1.Nodes
For x = .Count To 1 Step -1
 .Remove x
Next x
End With
End Sub

Open in new window

0
 
LVL 9

Expert Comment

by:richard_hughes
ID: 33645331
Hello TeDeSm

tvwPreAlert.Nodes.Clear() should work. How are you adding the items?

Also, are you re-adding the items after you clear them, perhaps in Page_Load outside of a if(!this.IsPostBack) check?

Thanks,

Richard Hughes
0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33646319
Try

tvwPreAlert = New TreeView
0
 

Author Closing Comment

by:TeDeSm
ID: 33646351
The treeview was being filled from a public arraylist. Clearing the array before re-filling handled the apparent append issue, BeginUpdate and EndUpdate dealt with the treeview nodes.
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question