473,770 Members | 5,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.node s.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.Ge tValue(0))
levelpart = CStr(rdrCCOA.Ge tValue(1))
level = CInt(rdrCCOA.Ge tValue(2))
coalinekey = CInt(rdrCCOA.Ge tValue(3))
acctno = CStr(rdrCCOA.Ge tValue(4))

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

Case Else 'add below that node
If IsNothing(paren tNode) Then Throw New
Exception("deep node found with no parent")
parentNode = findNode(acctTr ee, levelname)
If IsNothing(paren tNode) Then 'not already
present, add it
newNode = New TreeNode(leveln ame)
parentNode.Node s.Add(newNode)
parentNode = newNode
End If
End Select
End While
Nov 19 '05 #1
1 2873
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.Nod es.Add)

In your example below you do the following:
parentNode = findNode(acctTr ee, levelname)
If IsNothing(paren tNode) Then 'not already
present, add it
newNode = New TreeNode(leveln ame)
parentNode.Node s.Add(newNode)
parentNode = newNode
End If
If the findNode method returns Nothing then IsNothing will return True and you will end up calling parentNode.Node s 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***@langhors t.com>
Sender: "brad langhorst" <br***@langhors t.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+MPmdQcRuE 6QE+ymSh95WPH+A ==
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
Path: cpmsftngxa06.ph x.gbl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:130143
NNTP-Posting-Host: TK2MSFTNGXA06 10.40.1.53
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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.node s.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.Ge tValue(0))
levelpart = CStr(rdrCCOA.Ge tValue(1))
level = CInt(rdrCCOA.Ge tValue(2))
coalinekey = CInt(rdrCCOA.Ge tValue(3))
acctno = CStr(rdrCCOA.Ge tValue(4))

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

Case Else 'add below that node
If IsNothing(paren tNode) Then Throw New
Exception("dee p node found with no parent")
parentNode = findNode(acctTr ee, levelname)
If IsNothing(paren tNode) Then 'not already
present, add it
newNode = New TreeNode(leveln ame)
parentNode.Node s.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
1244
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: HeaderMenu.ForeColor = Drawing.Color.Black and
42
11556
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
4934
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. However, either it only add it to the root level or it only add it on level below, doesn't matter what I select. And in some case, I just get an exception.
14
15097
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
904
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 System.Windows.Forms.TreeNode() servernode.Text = NodtTemplate.Attributes(0).InnerText servernode.Tag = NodtTemplate.FirstChild.InnerXml --------------------
1
1280
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 other classes that are displayed on the treeview. How can i "cath" the link clicked event to choose how will be the next webpage generated by my program? It's just client side, has no servers at all.
0
1016
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 a TreeView. If I try to derive a class as follows public class MyTreeNode : TreeNode { }
8
12776
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 form. I only want to allow single selection, so using checkboxes is out of the question. It works as is, but it makes the form very cumbersome if every time that a user selects a node, the whole page has to reload. Is there a way to have a node...
1
1642
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 following syntax: Dim tNode as TreeNode = New TreeNode("root") tNode.name = "root" TreeView1.Nodes.Add(tNode) Now that I've gotten my root node set, I proceed to pass this node to another sub where some children are loaded to the node. The node is...
0
9432
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10232
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8891
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7420
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2822
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.