Home All Groups Group Topic Archive Search About

TreeNode.Remove(Boolean notify) exception

Author
5 Feb 2006 6:26 PM
Boni
Dear all,
I have a tree node inherited from TreeNode class. Sometimes when I call
Nodes.Clear() I get following exception.
I use .NET 2.0.50727.
Seems to be MS bug?
Any ideas?
Thanks
Boni

System.NullReferenceException: Object reference not set to an instance of an
object.
   at System.Windows.Forms.TreeNode.Remove(Boolean notify)
   at System.Windows.Forms.TreeNode.Clear()
   at System.Windows.Forms.TreeNodeCollection.Clear()

Author
5 Feb 2006 8:57 PM
Chris
Boni wrote:
Show quoteHide quote
> Dear all,
> I have a tree node inherited from TreeNode class. Sometimes when I call
> Nodes.Clear() I get following exception.
> I use .NET 2.0.50727.
> Seems to be MS bug?
> Any ideas?
> Thanks
> Boni
>
> System.NullReferenceException: Object reference not set to an instance of an
> object.
>    at System.Windows.Forms.TreeNode.Remove(Boolean notify)
>    at System.Windows.Forms.TreeNode.Clear()
>    at System.Windows.Forms.TreeNodeCollection.Clear()
>
>

It is telling you that "Nodes" is set to nothing when you are calling Clear.

Try this:

if Nodes isnot nothing Nodes.Clear