473,466 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

removing a treenode and its subnode

I've got a weird problem: when i try to delete a treenode containing subnodes the last node isn't removed: it gives the object reference not set to ... error.
Here's my code:

Dim lclsSubNode As clsSubNode
For Each lclsSubNode In pNode.Nodes
If Not lclsSubNode.Checked And Not lclsSubNode Is Nothing Then
'if checked don't delete
lclsSubNode.Remove()
End If
Next
If pNode.GetNodeCount(False) = 0 Then
'if mainnode doesn't conatin subnodes anymore, remove it
pNode.Remove()
End If

clsSubNode is a class that inherist of the Treenode class.
When there are two subnode everything works fine, when there are 3 or more i get the error when deleting the last node. So the function crashes in the for loop. Another weird thing is this: I've got a function that deletes 1 subnode only, when i try to delete the entire mainnode (including subnodes) the getnodecount values hasn't changed. So i delete a subnode of a mainnode havinf 3 nodes in total. You'd expect the getnodecount value to be 2 afterwards, but it still is three however the subnode has disappeared of the screen.
These nodes aren't linked to some datasource so that's not the problem.

I'm really out of ideas here, did i overlook something

Jul 21 '05 #1
0 877

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Benny Raymond | last post by:
More problems with this... When I run this code, the main form returns an invalid cast exception as it's executing the line "TreeNode n = (TreeNode) this.Nodes;" Does anyone know what would...
0
by: naija naija | last post by:
Hi All, I'm using the TreView Web Control for my MENU. And the Menu is populated from an XML file below. I want a way in which i can manipulate the XML when i want to manage it without having to...
0
by: Patrick.O.Ige | last post by:
I have this code below. All its suppose to do is to EXPAND / COLLAPSE ALL of my treeview. But when i use ASP.NET WEbmatrix it all works fine .. But with VS.NET is says TreeNodeCollection not...
3
by: markaelkins | last post by:
Hi. I am trying to enter a variable in the treenodesrc of a treenode. I am basically trying to send an ID variable into sql to return different records. I've searched everywhere and cannot find the...
0
by: scottwed | last post by:
I ran into an issue with the classic approach to synchronized checking of child nodes within a handler for the aftercheck event. After completing all the checkbox logic, I wanted to perform an...
2
by: alexandis | last post by:
Hi, i use xml sitemap, several big parent node groups. In each parentnode tag i want to specify url as initial 'selected' url to go to when loading the page. So i have the following structure...
0
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. ...
1
by: jmDesktop | last post by:
I am trying to add nodes with keys to my treeview. I can add general nodes without problem with: //create new node TreeNode newNode = new TreeNode(myIdNumber); //create children TreeNode...
1
by: AAaron123 | last post by:
If you see this posted twice - sorry. My news reader showed my first post as "No Longer Available" I have the following in a .css file. The treeNodes behave as if they were "a" elements. ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.