Solved

how to add TreeNode to TreeNodeCollection?

Posted on 2006-06-25
1
684 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
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…

763 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

16 Experts available now in Live!

Get 1:1 Help Now