Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to add TreeNode to TreeNodeCollection?

Posted on 2006-06-25
1
Medium Priority
?
725 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 150 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

598 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