Solved

how to add TreeNode to TreeNodeCollection?

Posted on 2006-06-25
1
706 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 86

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 …

726 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