[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 885
  • Last Modified:

VB.Net How to completely clear a TreeView

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
TeDeSm
Asked:
TeDeSm
1 Solution
 
DhaestCommented:
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
 
John (Yiannis) ToutountzoglouCommented:
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
 
richard_hughesCommented:
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
 
ZhaolaiCommented:
Try

tvwPreAlert = New TreeView
0
 
TeDeSmAuthor Commented:
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

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now