Solved

how to add TreeNode to TreeNodeCollection?

Posted on 2006-06-25
1
704 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 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