?
Solved

VB.Net How to completely clear a TreeView

Posted on 2010-09-10
5
Medium Priority
?
681 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

752 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