Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.Net How to completely clear a TreeView

Posted on 2010-09-10
5
Medium Priority
?
787 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

636 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