Results 1 to 4 of 4

Thread: Removing SubNodes - HELP!

  1. #1

    Thread Starter
    Hyperactive Member LeeSalter's Avatar
    Join Date
    Oct 2002
    Location
    Notts, England
    Posts
    307

    Removing SubNodes - HELP!

    I have this code in the AfterCollapse event of my TreeView control:-

    Code:
            Dim subNode As TreeNode
    
            For Each subNode In e.Node.Nodes
                MessageBox.Show("removing " & subNode.Text)
                subNode.Remove()
            Next
    
            e.Node.Nodes.Add("")
    I want the control to remove all sub-nodes after it has collapsed and then add a blank dummy one at the end.

    It falls over about half-way through with a "Object reference not set to an instance of an object" error.

    It appears to be trying to remove the same sub-node twice!
    Any ideas???
    "I'm Brian and so is my Wife"

  2. #2

    Thread Starter
    Hyperactive Member LeeSalter's Avatar
    Join Date
    Oct 2002
    Location
    Notts, England
    Posts
    307

    Removing SubNodes - RESOLVED

    Did it this way instead:-

    Code:
            Dim i As Integer
            For i = 1 To e.Node.GetNodeCount(False)
                e.Node.Nodes.RemoveAt(0)
            Next
    
            e.Node.Nodes.Add("")
    Cheers.
    "I'm Brian and so is my Wife"

  3. #3
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Have you tried
    VB Code:
    1. e.Node.Nodes.Clear
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  4. #4

    Thread Starter
    Hyperactive Member LeeSalter's Avatar
    Join Date
    Oct 2002
    Location
    Notts, England
    Posts
    307
    Cheers Pax!

    I AM a compelte idiot!
    Sometimes I think I'm half-decent at doing this......then along comes something like this to remind me that I am a complete dufus at it every now and again.
    "I'm Brian and so is my Wife"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width