Tree View - Help

Discussion in 'Questions (Windows Mobile)' started by Cableguy, Jun 2, 2008.

  1. Cableguy

    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)
  2. Erel

    Erel Administrator Staff Member Licensed User

    Something like:
    node1.Value = tree.SelectedNode
    "some text")
  3. Cableguy

    Cableguy Expert Licensed User

    I was so close and yet so far...
    I tryied:
    Node1.Value=Node2.New Node

    Wich of course didn't work....

    Thanks Erel
  4. Cableguy

    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?
  5. Erel

    Erel Administrator Staff Member Licensed User

    Can you upload your project?
    Tree.RemoveAllNodes should remove all nodes.
  6. Cableguy

    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...

    Attached Files:

  7. Cableguy

    Cableguy Expert Licensed User

    Got it working, using RemoveAllNodes, but I would hav sworn, i had already tried it, and failled....
  8. Cableguy

    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...

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

  9. Erel

    Erel Administrator Staff Member Licensed User

    See the attached example.

    Attached Files:

    • 1.sbp
      File size:
      1.4 KB
  10. Cableguy

    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...

    BUT Category can only be one level deep..
    XX|-Category02 - Cannot exist

    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

    Attached Files:

  11. Erel

    Erel Administrator Staff Member Licensed User

    To limit it to two levels you can use something like:
    Sub btnAdd_Click
    If IsNull(tree.SelectedNode) Then
    Msgbox("Please select a node.")
    End If
    node.Value = tree.SelectedNode
    If Not(node.IsRoot) Then
    Msgbox("too deep!")
    End If
    End Sub
  12. Cableguy

    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

    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?
  13. Erel

    Erel Administrator Staff Member Licensed User

    Node.IndexOfNode returns the index of the node related to his parent.
  14. Cableguy

    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....
  15. Cableguy

    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 :

    INI File:


  16. Cableguy

    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:

    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...
    Index = Node.IndexOfNode(Tree.SelectedNode)
    Index = Tree.IndexOfNode(
    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
  17. specci48

    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:

    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...

  18. Cableguy

    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????

    If Node.IsRoot Then
    Parent.Value = 
    Parent.Value = 
    End If
    Level = 
    Do While Not(Parent.IsRoot)
    level = level + 
    Parent.Value = Parent.Parent
    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: Jul 19, 2008
  19. Cableguy

    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...

    If Node.IsRoot Then Return
    Parent.Value = 
    Index = Parent.IndexOfNode(
    If Index <= 0 Then Return
    Parent.InsertNode(Index - 
    Thanks for your help so far guys, surelly more questions will arise, as treeview is NOT a simple control to workwith.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice