B4J Question Questions about TreeTableView

Mashiane

Expert
Licensed User
Longtime User
Hi

A couple of questions for clarity and request for help?

Q1. How can I set a "tag" for each TreeTableItem, I see there is no way to make each TreeTableItem have a unique id?
Q2. How does one search for a TreeTableItem by "text" and return the TreeTableItem? For example Id like to use AddChild(parentID, childID, childText), where the parentID will be a unique identifier for the parent.
Q3. Is it possible to move an item up / down or right / left using code?
Q4. Is it possible to get the position of a TreeTableItem within the tree?
Q6. When having added a context menu... how do I get the TreeTableItem the mouse actioned on?

1695521556603.png


Q7. How do I delete a TreeTableItem via code?

Thank you so much in advance.
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Q1. TreeItem does not have a tag implementation as it does not inherit from Node. You could keep your own Map to achieve this.
Q2. You could traverse the tree starting at root to find an item by text, or you could put that in a map as well.
Q3. Yes by removing it from it's current parent or position in the parents children and inserting it where you want it.
Q4. as Q2
Q5?
Q6. in the action call on the context menu, you can get the Source item from the Event getSource method (using JavaObject)
Q7. Remove it from it's parent.

Most of this depends on being able to identify the parent and it's position within it's parent. A Map and searching the parents items will go a long way to giving you the information you need.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Q5.

You can do something like this:
B4X:
    Dim L As List
    L.Initialize
    L.Add("A")
    L.Add("B")
    L.Add("C")
    L.Add("D")
    L.Add("E")
    
    Dim TTI As TreeTableItem
    TTI.Initialize("TTi", L.As(JavaObject).RunMethod("toArray",Null))
    
    For i = 0 To L.Size - 1
        Log(TTI.GetValue(i))
    Next
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If you have the TreeItem, You can get the parent until you get to the root level.

Something like.
B4X:
Dim TTI As TreeTableItem = SourceTTI
    Dim Level As Int
    Do While TTI.Parent.Root = False
       Dim TTI As TreeTableItem = TTI.Parent
        Level = Level + 1
    Loop
   
    Log(Level)

You could also capture the parents to a list. Or put them in the Map when you build it in the first place. Although you would have to maintain that when you move the nodes about.
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
You could also capture the parents to a list. Or put them in the Map when you build it in the first place. Although you would have to maintain that when you move the nodes about.
I am using 2 maps inside to manage the internal structure,

I have defined a schema like this

B4X:
tv.AddItem("", "prj1", "Anele Mbanga (Mashy)", Array("A","B","C","D","E"))
    tv.AddItem("prj1", "page1", "Page 1", Array("A","B","C","D","E"))
    tv.AddItem("prj1", "page2", "Page 2", Array("A","B","C","D","E"))
    tv.AddItem("prj1", "page3", "Page 3", Array("A","B","C","D","E"))
    tv.AddItem("page1", "page4", "Page 4", Array("A","B","C","D","E"))
    tv.AddItem("page1", "page5", "Page 5", Array("A","B","C","D","E"))
    tv.AddItem("page1", "page6", "Page 6", Array("A","B","C","D","E"))
    'search

Assumptions made are : the id and name are unique, because I need to search by id and also search by name. So far its doing stufff as planned.

Thank you so much @stevel05 for the help, appreciated. I might ask a lot of other questions... ;)
 
Upvote 0
Top