-
Apr 9th, 2008, 04:14 PM
#1
Thread Starter
Addicted Member
Delete selected tree node...
I have a treeview control that looks like this:
- Simon
-- Line
-- Circle
-- Rectangle
If the "Cirlce" node is selected I was wondering how I would delete that node using vb.net?
Thanks in advance
Simon
-
Apr 9th, 2008, 04:40 PM
#2
Addicted Member
Re: Delete selected tree node...
This should get the job done.
Code:
.Nodes.Remove(.SelectedNode)
-
Apr 9th, 2008, 04:44 PM
#3
Re: Delete selected tree node...
How to: Add and Remove Nodes with the Windows Forms TreeView Control
http://msdn2.microsoft.com/en-us/library/70w4awc4.aspx
-
Apr 9th, 2008, 06:32 PM
#4
Frenzied Member
Re: Delete selected tree node...
Simple...
Code:
tvTreeView.SelectedNode.Remove()
(tvTreeView is to be replaced by your tree view)
On what event you want to remove the node, is up to you...
if you want it to actually delete when it's selected, then you can add this code:
Code:
Private Sub tvTreeView_AfterSelect(ByVal sender As Object, ByVal e As TreeViewEventArgs) Handles tvTreeView.AfterSelect
e.Node.Remove() 'This might error if you have no nodes..
End Sub
Cheers
Icyculyr
-
Apr 10th, 2008, 04:27 AM
#5
Thread Starter
Addicted Member
Re: Delete selected tree node...
Thanks for your help however I have found a slight problem with the way that I am working.
I have a treeView which contains a number of nodes and also have a pictureBox, what I am doing is deleting the node element from within the pictureBox using a contextMenuStrip. This therefore means that the treeView loses focus. When I use your code it gives me a nullReferenceException on code I guess this is because the node is note focued? However if I execute your code from a contextMenuStrip on the treeView it works fine.
How can I get around this problem??
FYI: I have set the hideSelection to false
Thanks in advance
Simon
-
Apr 10th, 2008, 05:37 AM
#6
Re: Delete selected tree node...
Show us YOUR code and point out EXACTLY where the error occurs.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|