473,396 Members | 1,968 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,396 software developers and data experts.

Recursive TreeView Node Generator (VB 2005)

Might anyone be able to assist me with writing a (hopefully) simple program to generate an "outline" of successively imbedded nodes, ideally for Visual Basic 2005? Although the recursive technique is the part I'm wrestling with (and thus could probably figure out the rest) the ideal input would be a global one dimensional array containing the number of nodes at each level (0=stop), for instance level[4]=3,2,1,0 would generate the following text/node tree (minus the leading dots, which merely denote indentation)

1.
...1.1
......1.1.1
...1.2
......1.1.2
2.
...2.1
......2.1.1
...2.2
......2.2.1
3.
...3.1
......3.1.1
...3.2
......3.2.1


As yet I haven't figured out how to add child nodes directly using VB 2005, but defining a variable as type "TreeNode" and then adding nodes successively works, but if anyone knows how to do this more directly, please let me know. (I've noticed there are additional 'overload' parameters allowed in the 'Add' command, but I haven't been able to make them work for this purpose.)

Dim rootNode, childNode as TreeNode
Dim rootName, childName as String

rootName="1"
childname="1.1"

rootNode=TreeView1.Nodes.Add(RootName)
childNode=rootNode.Nodes.Add(childName)

Finally, does anyone know how to set individual node text color in VB 2005?

Thanks much,
Chris
Feb 24 '06 #1
1 6978
1.
...1.1
......1.1.1
...1.2
......1.2.1
2.
...2.1
......2.1.1
...2.2
......2.2.1
3.
...3.1
......3.1.1
...3.2
......3.2.1

my quick solution returns the above..

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim Levels As Int32 = 3
  3. Dim c1 As Int32 = 1
  4. Dim c2 As Int32 = 2
  5.  
  6. For loopy As Int32 = 1 To Levels
  7.     Dim RootNode As New TreeNode
  8.     RootNode = tv.Nodes.Add(loopy.ToString)
  9.     RootNode.ForeColor = Color.Red
  10.     For i2 As Int32 = 1 To c2
  11.         Dim ChildNode2 As New TreeNode
  12.         ChildNode2 = RootNode.Nodes.Add(loopy.ToString & "." & i2.ToString)
  13.         ChildNode2.ForeColor = Color.Blue
  14.  
  15.         For i3 As Int32 = 1 To c1
  16.             Dim ChildNode3 As New TreeNode
  17.             ChildNode3 = ChildNode2.Nodes.Add(loopy.ToString & "." & i2.ToString & "." & i3.ToString)
  18.            ChildNode3.ForeColor = Color.Green
  19.         Next
  20.     Next
  21. Next
  22.  
  23. tv.ExpandAll()
  24.  
-----------------------------------------------------------------------------

Might anyone be able to assist me with writing a (hopefully) simple program to generate an "outline" of successively imbedded nodes, ideally for Visual Basic 2005? Although the recursive technique is the part I'm wrestling with (and thus could probably figure out the rest) the ideal input would be a global one dimensional array containing the number of nodes at each level (0=stop), for instance level[4]=3,2,1,0 would generate the following text/node tree (minus the leading dots, which merely denote indentation)

1.
...1.1
......1.1.1
...1.2
......1.1.2
2.
...2.1
......2.1.1
...2.2
......2.2.1
3.
...3.1
......3.1.1
...3.2
......3.2.1


As yet I haven't figured out how to add child nodes directly using VB 2005, but defining a variable as type "TreeNode" and then adding nodes successively works, but if anyone knows how to do this more directly, please let me know. (I've noticed there are additional 'overload' parameters allowed in the 'Add' command, but I haven't been able to make them work for this purpose.)

Dim rootNode, childNode as TreeNode
Dim rootName, childName as String

rootName="1"
childname="1.1"

rootNode=TreeView1.Nodes.Add(RootName)
childNode=rootNode.Nodes.Add(childName)

Finally, does anyone know how to set individual node text color in VB 2005?

Thanks much,
Chris
Aug 14 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Saradhi | last post by:
Hi All, Here I am facing a performance problem with the TreeView Node renaming. I am displaying a hierarchy Data in a treeview in my Windows C# Application. My tree view represents an...
1
by: JustinG | last post by:
I am relativley new to C#, and I am trying to write code using the compact framework, that will allow a handheld user to hit enter while a treeview node is selected, which will then do something...
6
by: Tim | last post by:
Hi I have a form with a treeview on it. When I select a particular node it adds/shows a tab on the form. The treeview node remains selected as it should. The user can close the tab or remove the...
4
by: Yavuz Bogazci | last post by:
Hi, i have created a treeview and this works nice. I have now a problem: I want to store 2 more Information to each Treeview Node like UserID and CompanyID. How can i do that? Thanks Yavuz...
8
by: Don Wash | last post by:
Hi There! I'm using VB.NET to create a TreeView application and unfortunately I could not find "Key" property in Node items of the TreeView. We used to have "Key" property in TreeView node...
2
by: Christian Rühl | last post by:
heyho, guys! here's another question for you now: i built an iterator to get all the nodes with a certain attribute in an xml dom. it all looks like this (i'm using .NET framework 1.1) ...
1
by: watsod1 | last post by:
Hello, This is my first post, Hello to all. This also a test post to make sure that I am doing the right thing and following rules etc. I have been searching for a way to make the treeview...
3
by: Michael_Burgess | last post by:
Hi there, I've looked around the different groups and still can't figure this out without resorting to scrappy code............ I want to programtically select and highlight a TreeView node,...
1
by: R.A.F. | last post by:
Hi, I would like simulate a mouse click on on of my treeview nodes when my form opens. for that i was thinking to use the same simple way as under C++ : SendMessage(TreeView.Nodes.Handle,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.