Re: Solved: Remove a Node from TreeView?
From: Alex Feinman [MVP] (public_news_at_alexfeinman.com)
Date: 10/24/04
- Next message: Elie: "Re: a simple threading question"
- Previous message: Alex Feinman [MVP]: "Re: WinCE emulator and SqlServer"
- In reply to: Nicky Smith: "Solved: Remove a Node from TreeView?"
- Next in thread: Nicky Smith: "Re: Solved: Remove a Node from TreeView?"
- Reply: Nicky Smith: "Re: Solved: Remove a Node from TreeView?"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 24 Oct 2004 00:21:16 -0700
Why do you expect to be able to remove a non-root node by calling Remove on
the treeview itself?
When you add a node, you add it to TreeView.Nodes(0).Nodes
When you remove it, you should be removing it by calling
TreeView.Nodes(0).Nodes.Remove and not TreeView.Nodes.Remove.
You get OutOfRangeException because the node does not belong to a collection
from which you are trying to remove it.
Alternatively you can use
if TreeView.SelectedNode.ParentNode Is Nothing then
TreeView.Nodes.Remove(TreeView.SelectedNode)
else
TreeView.SelectedNode.ParentNode.Remove(TreeView.SelectedNode)
end if
-- Alex Feinman --- Visit http://www.opennetcf.org "Nicky Smith" <nixdk@yahoo.dk> wrote in message news:fb5ln0hg8t95avnuqjcgd7h2mu5ghmne9e@4ax.com... > > Hello, > > I've found a workaround for this bug (and it is a bug!) > > You can't call the remove method of the parent node, but you can call > the .Remove method of the reference node: > > This raises the error: > > Dim TN As TreeNode = TV1.SelectedNode > TV1.Nodes.Remove(TN) > > This works as expected: > > Dim TN As TreeNode = TV1.SelectedNode > TN.Remove() > > I've tried this on the emulator without SP1 or 2 and on a device with > SP2 and the bug exists in both scenarios. > > The .Remove method is documented in the .Net msdn help files using the > first version with a reference as an argument for the remove method. > (.remove(tn)) > > -N > > > > > On Sat, 23 Oct 2004 13:03:30 +0200, Nicky Smith <nixdk@yahoo.dk> > wrote: > >>Hello, >> >>I've got a problem with a TreeView. I get a starnge error when trying >>to call the .Remove method. >> >>The method is called from a ContextMenu, when holding the stylus down >>on a childnode. >> >>I then call the Remove method like this: >> >>If MessageBox.Show("Are you sure?", "Delete Item?", >>MessageBoxButtons.YesNoCancel, _ >> MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) >>= DialogResult.Yes Then >> Dim TN As TreeNode = TV1.SelectedNode >> >> TV1.Nodes.Remove(TN) >> >>End If >> >>This throws an Arguement Out of Range exception, on the call to >>Remove(). I don't undeerstand that, because the TN object does become >>a valid tree node, and the Remove method accepts a TreeNode as an >>argument! >> >>What am I doing wrong? >
- Next message: Elie: "Re: a simple threading question"
- Previous message: Alex Feinman [MVP]: "Re: WinCE emulator and SqlServer"
- In reply to: Nicky Smith: "Solved: Remove a Node from TreeView?"
- Next in thread: Nicky Smith: "Re: Solved: Remove a Node from TreeView?"
- Reply: Nicky Smith: "Re: Solved: Remove a Node from TreeView?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|