I am trying to add some items to a TreeView Control:
TV1.Nodes.Add("key1", "Test1") 'Works
TV1.Nodes("key1").Nodes.Add("key2", "Test2") 'Works (Nested)
TV1.Nodes("key2").Nodes.Add("key3", "Test3") 'Error (NullReferenceException)
any ideas? thanks :)
Here is a simple way..
http://msdn.microsoft.com/en-us/library/system.windows.forms.treenode.parent.aspx
You can make it even simpler - Just use the IsNot check and go ahead to add if the parent node exists.
BlueColorMan
Assuming that the structure you want looks like:
the final line should be:
TV1.Nodes("key1").Nodes("key2").Nodes.Add("key3", "Test3")
Or with
Use
TV1.Nodes("key1").Nodes.Add("key3", "Test3")
I figured it out myself: