Solved

VB.Net How to completely clear a TreeView

Posted on 2010-09-10
5
505 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

810 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