.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add Treeview Node : Object reference not set to an instance of an object

7 REPLIES 7
Reply
Message 1 of 8
jimmydee
3693 Views, 7 Replies

Add Treeview Node : Object reference not set to an instance of an object

I’m trying to convert some VBA utilities to VB.net and I’m having some trouble.

I’ve successfully setup a palette which contains a treeview and I’m trying to populate the treeview from another form, but when the code tries to add a node to the treeview I receive the following error.

“System.NullReferenceException: Object reference not set to an instance of an object.”

I have attached the code (Text File) for the form that I’m using to populate the treeview.

Can anyone help shine some light on what I’m doing wrong.

Thank you
Jim
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: jimmydee

You haven't shown enough to diagnose the problem, but I
suspect that it's happeing because You're trying to use the
TreeView from another thread, or that you have multiple
palettes and you're referencing the wrong one. Is your
palette assigned to a shared variable?


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6364417@discussion.autodesk.com...
I'm trying to convert some VBA utilities to VB.net and I'm having some trouble.

I've successfully setup a palette which contains a treeview and I'm trying to
populate the treeview from another form, but when the code tries to add a node
to the treeview I receive the following error.

"System.NullReferenceException: Object reference not set to an instance of an
object."

I have attached the code (Text File) for the form that I'm using to populate the
treeview.

Can anyone help shine some light on what I'm doing wrong.

Thank you
Jim
Message 3 of 8
jimmydee
in reply to: jimmydee

Tony,

Thank you for the quick reply. I've attached the code for the palette to this message. If you could take a quick look I would really appreciate it. I only have one paletteset with one palette. The palette contains UserControl1, and UserControl1 contains TreeView1 which is where I'm trying to add the Node.

Thanks again.
Jim
Message 4 of 8
Anonymous
in reply to: jimmydee

There doesn't seem to be any problem with that code,
so I would have to guess that the problem is here:

{code}

Dim NewNode As TreeNode =
TV1.Nodes(TV1.SelectedNode.Parent.Index).Nodes.Add("Layer", LayerName, 1, 3)

{code}

That's not a good way to do it. If you're trying to add
a 'sibling' to the selected node, then just use the
SelectedNode's Parent property, and make sure that
the selected node is not a root node, because if it is,
its Parent property will be Nothing.

{code}

Dim parent As TreeNode = TV1.SelectedNode
If Not IsNothing( parent ) Then
parent.Nodes.Add( new TreeNode("Layer", ...))
End If

{code}

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6364715@discussion.autodesk.com...
Tony,

Thank you for the quick reply. I've attached the code for the palette to this
message. If you could take a quick look I would really appreciate it. I only
have one paletteset with one palette. The palette contains UserControl1, and
UserControl1 contains TreeView1 which is where I'm trying to add the Node.

Thanks again.
Jim
Message 5 of 8
jimmydee
in reply to: jimmydee

Thank you Tony!

That got me going in the right direction.

Thanks again,
Jim
Message 6 of 8
cadcamm99
in reply to: Anonymous

When I type in:

 

Dim NewNode As TreeNode =

 

TreeNodes does not pop up in the common list. Do I need to import something to get it to pop up.  If I continue with the entire statement I get the error TreeNode is not defined.

 

I am useing VB 2008 Express Edition.

Message 7 of 8
fieldguy
in reply to: jimmydee

Add reference to System.Windows.Forms.  Add Imports System.Windows.Forms.

Message 8 of 8
cadcamm99
in reply to: fieldguy

Thanks.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost