I have a treeview structured as such:
the 2nd Child nodes are added at Runtime, based on information pulled from the SQL query. Thats all great and fine, but when I want to run a new query, I need for the 2nd Child nodes to Be gone.
Here is the code I wrote to remove the 2nd child nodes:
For Each t As TreeNode In TreeView1.Nodes 'loop through parent nodes
For Each c As TreeNode In t.Nodes 'loop through 1st child nodes
For Each d As TreeNode In c.Nodes 'loop through 2nd child nodes
d.Remove() 'remove child node System.NullRefException
as I step through this code it works fine until it gets to one particular 1st child node that has 5 child nodes under it. It runs through 3 of those 2nd child nodes and removes them like it's supposed to, but then it throws a NullReference exception... "Object reference not setto an instance of an object". I dont understand why all of a sudden it loses the object reference that it just had.????