473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

trouble with a treeview add

I'm going over a result set and adding results as levels on
the tree control.

when stepping through the code i see execution switch to
the calling subroutine as soon as the parentnode.nodes.add
is called. Seems like i'm trampling some variable (btw:
why doesn't that raise an error?)

I'm a fairly experienced programmer but i'm new to vb.net
so maybe this is something trivial...

here's my code

While rdrCCOA.Read
'results must be ordered by coalinekey and name to work

levelname = CStr(rdrCCOA.GetValue(0))
levelpart = CStr(rdrCCOA.GetValue(1))
level = CInt(rdrCCOA.GetValue(2))
coalinekey = CInt(rdrCCOA.GetValue(3))
acctno = CStr(rdrCCOA.GetValue(4))

'keep adding until coalinekey changes
Select Case level
Case 1 'create new root node if this one is not
already there
parentNode = findNode(acctTree, levelname)
If (IsNothing(parentNode)) Then 'not already
present add it
parentNode = New TreeNode(levelname)
acctTree.Nodes.Add(parentNode)
End If

Case Else 'add below that node
If IsNothing(parentNode) Then Throw New
Exception("deep node found with no parent")
parentNode = findNode(acctTree, levelname)
If IsNothing(parentNode) Then 'not already
present, add it
newNode = New TreeNode(levelname)
parentNode.Nodes.Add(newNode)
parentNode = newNode
End If
End Select
End While
Nov 19 '05 #1
1 2863
Hello Brad,

when the code steps out suddently like this, it often indicates that an exception occured. You could try to run your program under the debugger and turn on
the "Break on exceptions" feature. Here's how to do it once VS is in debug mode:

1. Go to the Debug/Exceptions... menu
2. Click on the "Common Language Runtime Exceptions" item.
3. Set the option for "When an exception is thrown" at the bottom of the dialog to "Break into the debugger"
4. Execute the line of code in question (parentNode.Nodes.Add)

In your example below you do the following:
parentNode = findNode(acctTree, levelname)
If IsNothing(parentNode) Then 'not already
present, add it
newNode = New TreeNode(levelname)
parentNode.Nodes.Add(newNode)
parentNode = newNode
End If
If the findNode method returns Nothing then IsNothing will return True and you will end up calling parentNode.Nodes with an invalid reference. So the
problem you're having might be caused by an 'Object reference not set' exception.

HTH

Antoine
Microsoft Visual Basic .NET

--------------------Content-Class: urn:content-classes:message
From: "brad langhorst" <br***@langhorst.com>
Sender: "brad langhorst" <br***@langhorst.com>
Subject: trouble with a treeview add
Date: Sun, 24 Aug 2003 22:15:23 -0700
Lines: 45
Message-ID: <27****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcNqx+MPmdQcRuE6QE+ymSh95WPH+A==
Newsgroups: microsoft.public.dotnet.languages.vb
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:130143
NNTP-Posting-Host: TK2MSFTNGXA06 10.40.1.53
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I'm going over a result set and adding results as levels on
the tree control.

when stepping through the code i see execution switch to
the calling subroutine as soon as the parentnode.nodes.add
is called. Seems like i'm trampling some variable (btw:
why doesn't that raise an error?)

I'm a fairly experienced programmer but i'm new to vb.net
so maybe this is something trivial...

here's my code

While rdrCCOA.Read
'results must be ordered by coalinekey and name to work

levelname = CStr(rdrCCOA.GetValue(0))
levelpart = CStr(rdrCCOA.GetValue(1))
level = CInt(rdrCCOA.GetValue(2))
coalinekey = CInt(rdrCCOA.GetValue(3))
acctno = CStr(rdrCCOA.GetValue(4))

'keep adding until coalinekey changes
Select Case level
Case 1 'create new root node if this one is not
already there
parentNode = findNode(acctTree, levelname)
If (IsNothing(parentNode)) Then 'not already
present add it
parentNode = New TreeNode(levelname)
acctTree.Nodes.Add(parentNode)
End If

Case Else 'add below that node
If IsNothing(parentNode) Then Throw New
Exception("deep node found with no parent")
parentNode = findNode(acctTree, levelname)
If IsNothing(parentNode) Then 'not already
present, add it
newNode = New TreeNode(levelname)
parentNode.Nodes.Add(newNode)
parentNode = newNode
End If
End Select
End While

--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: TomSt | last post by:
Hello, I'm trying to set the ForeColor property on a Menu and and a TreeView using ASP.Net 2.0 and VisualStudio 2005 Beta. This is a VB.Net app Here are the code snippet: ...
42
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
6
by: L.M | last post by:
Hello, I knew how to use the treeview under VB6. After migrating to .NET, well, I'm lost. I try to add a new node, either to the same level or as a child to a selected node in the treeview....
14
by: Mr.D | last post by:
How do I save/load the contents of a Treeview to a file? I have found several good examples written i VB6, but not a single one for VB.NET. Please help. ---- Tim
0
by: samirtripathy | last post by:
I am loading data from a XML file and populating a TreeVew. I store certain values in the tags of the treevew nodes using the following code -------------------- Dim servernode As New...
1
by: Tomaz Canabrava | last post by:
kay, here it`s my problem. i have a TreeView and a WebBroswer, when i choose something on the treeview, the program generates an html, and it is showed on the webbroswer, but the html has links to...
0
by: David | last post by:
Hi, I've been working with TreeView for ASP.NET. I've had several puzzling difficulties with it. For example I can write an application that works fine programmatically adding TreeNode objects to...
8
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the...
1
by: JRSofty | last post by:
Hi everyone, I've gotten myself is bit of a mess where I'm loading a treeview. Basically I initialize the treeview control with a single root node we'll call it root. I do this by using the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.