Solved

how to add TreeNode to TreeNodeCollection?

Posted on 2006-06-25
1
694 Views
Last Modified: 2011-10-03
how to correctly add TreeNode to TreeNodeCollection? i have tried the following:

Dim tnc As TreeNodeCollection
Dim tn As New TreeNode
tn.Text = "TEST NODE"
tn.Nodes.Add("TEST SUBNODE")
tnc.Add(tn)

when i call this code i get System.NullRefernceException error 'Object reference not set to an instance of an object". however the TreeNodeCollection data type does not have constructors (i cannot use the New keyword). so how do i use the TreeNodeCollection? more generally, can i use TreeNodeCollection as a non-visual TreeView?
0
Comment
Question by:latsubs
1 Comment
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 16980764
You could always create a TreeView and just not add it to your form...

Public Class Form1

    Private tv As TreeView
    Private tnc As TreeNodeCollection

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        tv = New TreeView
        tnc = tv.Nodes

        Dim tn As New TreeNode
        tn.Text = "TEST NODE"
        tn.Nodes.Add("TEST SUBNODE")
        tnc.Add(tn)
    End Sub

End Class
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now