10 Replies - 280 Views - Last Post: 18 February 2019 - 01:24 PM Rate Topic: -----

#1 demac430   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 15
  • Joined: 04-January 14

Treeview iteration

Posted 18 February 2019 - 02:21 AM


I have a tree created at design time with 3 root nodes and 3 levels 3x3x3 =39 nodes as the default.

The nodes can be dynamically recreated.

When I cleared the nodes then recreated them, I tried looping through to add properties to the nodes of each level including their relevant context menu name.

	Private Sub RedoTree_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RedoTree.Click

		treeLoad()
		treeExecutive.ExpandAll()
		restoreTP()
		treeExecutive.Nodes(0).EnsureVisible()

	End Sub


Sub restoreTP() '				renew treenode properties

		Dim s As String, l As Short

		treeExecutive.Update()

		For Each treenode In treeExecutive.Nodes
			s = treenode.Name
			l = Len(s)
			treenode.ForeColor = Color.GhostWhite

			If treenode.Text <> s Then treenode.ForeColor = Color.Black

			Select Case l
				Case 1
					treenode.NodeFont = New Font("Arial Rounded MT Bold", 10.8)
					treenode.ContextMenuStrip = CMSRoot
				Case 2
					treenode.NodeFont = New Font("Arial", 10.2)
					treenode.ContextMenuStrip = CMSTree
				Case Else
					treenode.NodeFont = New Font("Arial Narrow", 9)
					treenode.ContextMenuStrip = CMSTree
			End Select

		Next

	End Sub



The root nodes are number 1-3, then 11,12,13 .... 111,112,113 Total is 39 nodes

ONLY THE ROOT NODES ARE RECOGNISED AND DEALT WITH.

All the child nodes are ignored as if they don't exist

Am bogged down on this and would appreciate any help


Is This A Good Question/Topic? 0
  • +

Replies To: Treeview iteration

#2 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6746
  • View blog
  • Posts: 27,775
  • Joined: 12-December 12

Re: Treeview iteration

Posted 18 February 2019 - 02:41 AM

Which part of your code do you think is where the issue is first apparent?

What do treeLoad() and treeExecutive.Update() do?
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6746
  • View blog
  • Posts: 27,775
  • Joined: 12-December 12

Re: Treeview iteration

Posted 18 February 2019 - 02:47 AM

Note that you do not need to increase the font size when posting, anyone who struggles to read the default size will probably already have zoomed in.
Was This Post Helpful? 0
  • +
  • -

#4 demac430   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 15
  • Joined: 04-January 14

Re: Treeview iteration

Posted 18 February 2019 - 03:07 AM

Hi

Thanks for your interest Andrew

Treeload is my subroutine to programmically reproduce all the nodes, which it does successfully.
My treeview name is treeExecutive - I thought an update might be required but did nothing

The 3 root nodes do update wrt their properties (when l=1), but the child nodes are ignored.

Demac
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6746
  • View blog
  • Posts: 27,775
  • Joined: 12-December 12

Re: Treeview iteration

Posted 18 February 2019 - 03:20 AM

Your question remains unclear to me personally, but you are basing a test on the length of treenode.Name, I don't think that can be right.

Please also use sensible names for variables, it took me a moment to recognise that Select Case l was an 'l', not a '1'.

Quote

All the child nodes are ignored as if they don't exist


How are you iterating child nodes?
Was This Post Helpful? 0
  • +
  • -

#6 demac430   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 15
  • Joined: 04-January 14

Re: Treeview iteration

Posted 18 February 2019 - 03:45 AM

Hi

By this statement
For Each treenode In treeExecutive.Nodes

I was asking the routine to examine every node.
Iterate here refers to looping through the routine.

Node.name is just a means of identification and works extremely well for me.
Node.text is the name a user can supply to the tree - get it?

My point is that the routine is Not including the child nodes in 'For Each treenode'

Leave it Andrew if you don'f follow.

thanks demac
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14862
  • View blog
  • Posts: 59,297
  • Joined: 12-June 08

Re: Treeview iteration

Posted 18 February 2019 - 08:03 AM

I would suggest putting a breakpoint on your for each and checking out the 'nodes' collection. Then examine the singular node. See how each node as a collection of nodes as well? You would need to exhaust those lists too.

Recursion comes to mind.
Was This Post Helpful? 1
  • +
  • -

#8 maceysoftware   User is offline

  • Member Title
  • member icon

Reputation: 369
  • View blog
  • Posts: 1,579
  • Joined: 07-September 13

Re: Treeview iteration

Posted 18 February 2019 - 08:06 AM

To navigate through a treeview to all nodes would require recursion.

Treeview.Nodes would give you the top Nodes.

Then from the top nodes, you can do TopNode.Nodes to give you the children of the top nodes

Basically, at each level house another ".nodes" which contains the level below, does that make sense?
Was This Post Helpful? 1
  • +
  • -

#9 demac430   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 15
  • Joined: 04-January 14

Re: Treeview iteration

Posted 18 February 2019 - 10:34 AM

Hi
thanks for your pointers everyone.

Decided that the simplest solution was to update node properties as I created them.

I can include this routine in another reply if anyone is interested.

Demac
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14862
  • View blog
  • Posts: 59,297
  • Joined: 12-June 08

Re: Treeview iteration

Posted 18 February 2019 - 10:47 AM

It's always helpful for future folk to include your solution in your post.
Was This Post Helpful? 0
  • +
  • -

#11 demac430   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 15
  • Joined: 04-January 14

Re: Treeview iteration

Posted 18 February 2019 - 01:24 PM

Hi

Here is my subroutine to create my default nodes

	Sub treeLoad()

		' Treeview named treeExecutive created at design time  300x500, indent 40, item height 22

		Dim root, child1, child2 As String

		For i = 1 To 3
			root = i

			Dim n1 = treeExecutive.Nodes.Find(root, True)

			nl = n1.Length

			If nl = 0 Then
				treeExecutive.Nodes.Add(root, root) '				key name = text name
				n1 = treeExecutive.Nodes.Find(root, True)
				n1.First.NodeFont = New Font("Arial Rounded MT Bold", 10.8)
				n1.First.ContextMenuStrip = CMSRoot	'		allows routines to Add a Root Node, Add a Child Node, delete a Node, rename, clear all
			End If

			For j = 1 To 3
				child1 = 10 * i + j

				Dim n2 = treeExecutive.Nodes.Find(child1, True)

				nl = n2.Length

				If nl = 0 Then
					treeExecutive.Nodes(root).Nodes.Add(child1, child1)
					n2 = treeExecutive.Nodes.Find(child1, True)
					n2.First.NodeFont = New Font("Arial", 10.2)
					n2.First.ContextMenuStrip = CMSTree	'		allows routines to Add a Child Node, delete a Node, rename, clear all
				End If

				For k = 1 To 3
					child2 = 10 * child1 + k

					Dim n3 = treeExecutive.Nodes.Find(child2.ToString, True)

					nl = n3.Length

					If nl = 0 Then
						treeExecutive.Nodes(root).Nodes(child1).Nodes.Add(child2, child2)
						n3 = treeExecutive.Nodes.Find(child2, True)
						n3.First.NodeFont = New Font("Arial Narrow", 9)
						n3.First.ContextMenuStrip = CMSTree
					End If
				Next
			Next
		Next

	End Sub



cheers demac
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1