B4J Question TreeView add children

atiaust

Active Member
Licensed User
Longtime User
Hi all,

I am trying to add children to treeview parents and sort them into the correct order.

eg treeView1 parents are 0,100,200,300 etc - children of 100 are 110,120,170
(root)
0
100
110
120
170
200
220
300
etc..

I want to add 150 as a child to parent (100) in its correct place in the list.

I can add it to the end of the list under parent 100 but can't get it in the correct place.

Any help will be gratefully accepted.

Thanks
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Hello!

Instead of add use insertAt This worked for me:

B4X:
    For i = 100 To 400 Step 100
        Dim t As TreeItem
        t.Initialize("",i)
        TreeView1.Root.Children.Add(t)
    Next
   
    Dim tI As TreeItem = TreeView1.Root.Children.Get(0)
   
    For i = 10 To 40 Step 10
        Dim t As TreeItem
        t.Initialize("",i)
        tI.Children.Add(t)
    Next
   
    For i = 60 To 90 Step 10
        Dim t As TreeItem
        t.Initialize("",i)
        tI.Children.Add(t)
    Next
   
    Dim t50 As TreeItem
    t50.Initialize("",50)
    tI.Children.InsertAt(4,t50)
 
Upvote 0

atiaust

Active Member
Licensed User
Longtime User
Thanks Enrique

That works for a treeView that is being built all at one time.

I need to add items after the treeView is completed.

InsertAt works but I need to find where to insert the new item in the child Index - ie ti.children.InsertAt(indexNo,t50).
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Ufff... you really put my brain on its knees but at least for your example i got it, you may want to polish the code
 

Attachments

  • example.zip
    2.4 KB · Views: 204
Upvote 0

atiaust

Active Member
Licensed User
Longtime User
Thanks

That gets me very close to what I was trying to achive.

I am trying to get the value of a child item.
When I use log("value = "&treeItem.children.get(i))
I get.. value = TreeItem [ value: 110 ] instead of 'value = 110'
Is there any way of getting the value only?
 
Upvote 0
Top