Tree View - Help

Cableguy

Expert
Licensed User
Been playing aroun with tree view...

How do I add a new node to the currently selected node
(i.e:Add a grandson to the selected grandparent, beetween several grandparents)
 

Cableguy

Expert
Licensed User
I was so close and yet so far...
I tryied:
Node1.Value=TV.SelectedNode
Node1.Value=Node2.New Node

Wich of course didn't work....

Thanks Erel
 

Cableguy

Expert
Licensed User
OK, so I got that working bit, now I need to remove all created nodes up to the root, clearing the tree object...
BUT, I do not wich to dispose of the treeview object...

I tryied Tree.RemoveAllNodes method, but nothing gets deleted...
What am I missing?
 

Cableguy

Expert
Licensed User
This is a work in progress so some bugs may occur or some part of code be missing..
only the spb file is uploaded...

baiscally, when the user shoses "New", I have to check if a file is in use and warn the user about it, if he cooses to continue, the the current treeview, should be cleared of all nodes and be made "Blank"....
Since it uses treeview, controlsEx.dll is required,lol...
 

Attachments

Cableguy

Expert
Licensed User
Got it working, using RemoveAllNodes, but I would hav sworn, i had already tried it, and failled....
 

Cableguy

Expert
Licensed User
Now another issue..

In order to have a context nemu, I was "forced" to add formlib...
Figured out how to add a context menu, so far so good...
New problems arise...

I seem to only need One Node Object to create how many sub-levels I want or need in the treeView...But I NEED to limit the node to 3 Levels...
Root,Category and Key asin Parent, son and grandson...
How?

And how do I delete a selected Node?
I tryied removenode, removenodeat with no success...

HELP???
 

Cableguy

Expert
Licensed User
Your example is almost perfect for my aplication, and I understand how the level catching works...
But I still have one issue(for the time being...)...

I have 1 Tree Object (tree) and 2 Node Objects(Parent and Node in order to make sense of your example...)
The 3 level limitation works great...but what is I wish to limit it to just 2 levels?
I tryed to alter your example but I got nowere...
Here's my project as is...
need both controlsEx and FormLib dlls...
My intension is:
Tree Root is the INI Filename (setted for now as Default.INI)
Key and Comment can exist in any alowed sub level...
ie:
+Default.INI
|--Key01
|--Comment01
+-Category01
XX|-Key02
XX|-Comment02

BUT Category can only be one level deep..
ie:
+Default.INI
|--Key01
|--Comment01
+-Category01
XX|-Key02
XX|-Comment02
XX|-Category02 - Cannot exist

PS:
Hopefully this will become a structured INI file creator, wich I believe will help those of us who relly on them for some settings...setting
 

Attachments

Cableguy

Expert
Licensed User
Thanks Erel...
Your help has been precious ...
One future problem in this project...
How are the node indexed?
Imagins this tr
Defaut.INI
|
+-[Categoty01]
|XXX|
|XXX+-Key02
|XXX+'Coment04
|
+-[Category02]
XXXX|
XXXX+Key01

Key01 was of course created before key02, but key02 is "read" before key01...
is the index automatically corrected, an the index of key02 is lower than index of key01, or will I need to make sure to read in the correct order?
 

Cableguy

Expert
Licensed User
Thanks, I rhink I understand....
I nedd to first catch the cat index related to the root and then catch the other nodes related to the categories....
cool....some cicles comming up....
 

Cableguy

Expert
Licensed User
Once more I need guidance working with the treeview...

I nedd to read a file(.INI) and, acording with some StrAt values, create the appropiate levels and sub-levels of the treeview nodes...
I have been to the point of being able to read and create all the read nodes, but all at the same level...

When i read an INI file, if it is a complex one, I have to be able to create the sub-levels, but how...I keep getting an error of "invalid reference " or whatever..

Example Treeview result :
+Default.INI
|--Key01
|--Comment01
+-Category01
XX|-Key02
XX|-Comment02
+-Category02
XX|-Key03
XX|-Comment03


INI File:
Key01
'Comment01

[Category01]
Key02
'Comment02

[Category02]
Key03
'Comment03
 

Cableguy

Expert
Licensed User
TreeView should be a more straight-foward, easy to understand control...

My current app, is based on this control, and i should have finish it a few weeks ago, but the vacations got in the way, along with some yet to resolve issues...
Now back to work, I need to clear some doubts...

Imagine this tree:
+Default.INI
|--Key01
|--Key02
|--Key03
|--Key04
|--Comment01
+-Category01
XX|-Key05
XX|-Comment02
+-Category02
XX|-Key06
XX|-Comment03

Now let's say I want to move The node "Comment01" up by 2 positions, to setle in beetwen of "Key02" and "Key03"..

I tryed to get the index of the selected node, as one must first select the node to be moved:sign0161:, but i keep getting a value of -1...

This is teh code and its variants I've used just to get the index of the selected node...
B4X:
Index = Node.IndexOfNode(Tree.SelectedNode)
Index = Tree.IndexOfNode(Node.value)
I want to be ale to move the nodes up and down, always related to its Parent.
My tree wil be no deeper that 2 levels...

Please HELP
 

specci48

Well-Known Member
Licensed User
Hello Cableguy,

I followed this thread for a while so after I finished my actual project now I uploaded my ToDoTree application here:
http://www.basic4ppc.com/forum/share-your-creations/2698-todotree-application.html#post14995

I think this could be a good demo for you showing how I solved the (little) problems I got dealing with the treeview... :sign0148:
Some comments in the program are still in german but it shouldn't be difficult "read" my application.
And of course feel free to ask futher questions if you need more explanation to the code...


specci48
 

Cableguy

Expert
Licensed User
Going Back to Erel's example, I was able to deternime the Level of the selected node....
And I am able to determine the index of level 1 nodes....But not level 2...What am I missing????

B4X:
If Node.IsRoot Then
Parent.Value = Node.Value
Else
Parent.Value = Node.Parent
End If
Level = 1
Do While Not(Parent.IsRoot)
level = level + 1
Parent.Value = Parent.Parent
Loop
MsgBox(level) 'Tels me the level of the selected Node, wich can be 1 or 2...
If Level = 1 Then
Index = Parent.IndexOfNode(TreeView.SelectedNode)'This works and I do get the index of the selected node on level 1
Else If Level = 2
Index = Node.IndexOfNode(TreeView.SelectedNode)'Can't Figure out how to get the index for level 2 nodes
End If
Msgbox(Index)'Level 2 nodes alway return -1 values
Thanks for all the help...
 
Last edited:

Cableguy

Expert
Licensed User
Well, as most of the time happens, I end up answering my own question, simple because i keep trying to squeeze the answers from my code...

SO, I got it working with lesser code than i could Imagine...

B4X:
If Node.IsRoot Then Return
Parent.Value = Node.Parent
Index = Parent.IndexOfNode(TreeView.SelectedNode)
If Index <= 0 Then Return
Parent.RemoveNodeAt(Index)
Parent.InsertNode(Index - 1,Node.Value)
Thanks for your help so far guys, surelly more questions will arise, as treeview is NOT a simple control to workwith.
 
Top