473,569 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically Created TreeView not expanding/collapsing

Hi-

I'm running this database query where the results will be used to
populate my treeview.

For Each drPA As DataRow In dsMasterList.Ta bles(0).Rows
iRoot = iRoot + 1
nRootNode = New TreeNode(drPA(0 ), iRoot, "", "", "")
nRootNode.Selec tAction = TreeNodeSelectA ction.Expand
tvMasterList.No des.Add(nRootNo de)
For Each drSubject As DataRow In
dsMasterList.Ta bles(1).Rows
If (drSubject(1) = nRootNode.Text) Then
iSub = iSub + 1
nSubNode = New TreeNode(drSubj ect(1), iSub, "",
"", "")
nRootNode.Child Nodes.Add(nSubN ode)
For Each drTopic As DataRow In
dsMasterList.Ta bles(2).Rows
If (drTopic(1) = nSubNode.Text) Then
iTopic = iTopic + 1
nTopicNode = New TreeNode(drTopi c(1),
iTopic, "", "", "")
nSubNode.ChildN odes.Add(nTopic Node)
End If
Next
'nSubNode.Expan d()
End If
Next
'tvMasterList.N odes.Add(nRootN ode)
'nRootNode.Expa nd()
Next

If I uncomment the expand functions, I can see that my code works
nicely, and the treeview is populated correctly. But it won't expand
or collapse! When I try it I get the following error in the IE
'debugger':

"Childnodes .0 is null or not an object"

I'm really lost here, any help will be greatly appreciated.
Feb 24 '08 #1
1 2658
This can be disregarded. I put the code inside of the form_load sub,
and it works perfectly.

On Feb 24, 4:46*pm, Chris <coz1...@gmail. comwrote:
Hi-

I'm running this database query where the resultswillbe used to
populate mytreeview.

For Each drPA As DataRow In dsMasterList.Ta bles(0).Rows
* * * * * * iRoot = iRoot + 1
* * * * * * nRootNode = New TreeNode(drPA(0 ), iRoot, "", "","")
* * * * * * nRootNode.Selec tAction = TreeNodeSelectA ction.Expand
* * * * * * tvMasterList.No des.Add(nRootNo de)
* * * * * * For Each drSubject As DataRow In
dsMasterList.Ta bles(1).Rows
* * * * * * * * If (drSubject(1) = nRootNode.Text) Then
* * * * * * * * * * iSub = iSub + 1
* * * * * * * * * * nSubNode = New TreeNode(drSubj ect(1), iSub, "",
"", "")
* * * * * * * * * * nRootNode.Child Nodes.Add(nSubN ode)
* * * * * * * * * * For Each drTopic As DataRow In
dsMasterList.Ta bles(2).Rows
* * * * * * * * * * * * If (drTopic(1) = nSubNode.Text) Then
* * * * * * * * * * * * * * iTopic = iTopic + 1
* * * * * * * * * * * * * * nTopicNode = NewTreeNode(drT opic(1),
iTopic, "", "", "")
* * * * * * * * * * * * * * nSubNode.ChildN odes.Add(nTopic Node)
* * * * * * * * * * * * End If
* * * * * * * * * * Next
* * * * * * * * * * 'nSubNode.Expan d()
* * * * * * * * End If
* * * * * * Next
* * * * * * 'tvMasterList.N odes.Add(nRootN ode)
* * * * * * 'nRootNode.Expa nd()
* * * * Next

If I uncomment theexpandfuncti ons, I can see that my code works
nicely, and thetreeviewis populated correctly. *But it won'texpand
or collapse! *When I try it I get the following error in the IE
'debugger':

"Childnodes .0 is null ornotan object"

I'm really lost here, any helpwillbe greatly appreciated.
Feb 25 '08 #2

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

Similar topics

0
1801
by: Mike Preston | last post by:
Warning - long message. Many thanks for making the A97 version of the treeview w/o activex controls available. I have taken it down a different path and ended up doing almost everything differently. It now has, built in, the ability to have 12 levels, not just 3. The tree's recordsource table (TreeviewRS) is built based on information
3
8829
by: Steve Richter | last post by:
in windows explorer, the nodes immed under the "my computer" root node appear with a minimum of indenting ( the +/- square is directly underneath the root node ). In the .NET TreeView control the indent is shifted one more indent level to the right, wasting valuable horizontal space. How can I instruct TreeView to indent from the root node...
3
10133
by: Jan Wrage | last post by:
Hi! I would like to implement a treeview in my existing application. It should show my entire Active-Directory structure, i.e. all Groups, Containers and OUs. Could somebody help me with that. Im trying for about 3 hours but can't get it to work. Thank you!
6
7353
by: Jack | last post by:
Hello, I would like some advice on how to disable the behavior of treeviews to expand and collapse when double clicked upon, but still allow the user to use the plus and minus on each node. Thanks in advance! Jack
1
9933
by: James L | last post by:
Hi, I have a treeview that has to be refreshed due to data changes. Is it possible to select the last node that they were viewing when the tree view was been populated once again? I have tried getting the selected node and then expanding it in the refreshed tree view using expand() but it does not do it. Thanks for any help.
0
991
by: rony_16 | last post by:
Hi, i have a problem with the webcontrol treeview in asp.net v2 . i want to save the state of expanding/collapsing of my tree after post back . i know that i can do that if i write "if (!ispostback)" ,but i can not , because i am building the tree all over again each time i am doing post back . Can you please help me with this problem .
3
5580
by: cowznofsky | last post by:
Rather than load all my data into the treeview I am loading when a level-1node gets expanded (for the first time). To set up the code below, I've added a single child node for each level-1node, just so that I can get the "+" and the capability to expand. So the first time I click on any level-1 node, it loads 30 child nodes. The...
13
2730
Chrisjc
by: Chrisjc | last post by:
I am in need of an expanding and collapsing code… The goal is To be able to click a PICTURE IMAGE and expand to show information Reason for this is I have 3 TABLES of information of about 400x200… that I want to be able to expand to how much information I put in them…. Just need a code that will cut it off and then OPEN it… So
1
5301
by: Jahedx99 | last post by:
Check out the site: www.progtalk.com. They have a great article to expand and collapse rows of a grid. The cool part it, that the expanding and collapsing happens using Javascript. I think the exact link is: http://www.progtalk.com/ViewArticle.aspx?ArticleID=1
0
8120
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7968
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...
1
5512
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...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
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
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
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...

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.