B4J Question TreeTableView manuel create problem

Tayfur

Well-Known Member
Licensed User
Longtime User
Hello;
I want create TreeTableView (TTV) own form.
After I add values copy from other TTV.
But I cant do it.
(other TTV is ok)
I tried root & cchildren intalize. But dont work. its gereallly "FALSE"

B4X:
TTV_agac.Initialize("TTV_agac")
    TTV_agac.SetSize(300,280)
    TTV_agac.RowHeight=40
    TTV_agac.Root.Initialize("",Array As String("1","2"))
    MForm.RootPane.AddNode(TTV_agac,0,0,(PL.GetPrintableWidth-10)/2,280)
    TTV_agac.Root.Children.AddAll(OLDtabletriView.Children)

Log:
 

stevel05

Expert
Licensed User
Longtime User
You haven't posted and error messages but It looks like you are trying to copy children from another view. This is unlikely to work as views can have only 1 parent. You would either have to remove them from the original view, clone them and all of their children or create new ones the same way as you populated the first table.
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
You haven't posted and error messages but It looks like you are trying to copy children from another view. This is unlikely to work as views can have only 1 parent. You would either have to remove them from the original view, clone them and all of their children or create new ones the same way as you populated the first table.

This sample based/devlped of Library sample

B4X:
#Region Project Attributes
    #MainFormWidth: 800
    #MainFormHeight: 800
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private TreeTableView1 As TreeTableView
    Private TTV_agac As TreeTableView
    Private lblSelectedItem As Label
    Private FolderImage As Image
    Private btnItem As Button
    Private btnListSelected As Button
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    MainForm.RootPane.LoadLayout("1")
    FolderImage = fx.LoadImage(File.DirAssets, "Folder.png")
    AddFolder(TreeTableView1.Root, File.DirApp)
    TreeTableView1.RowHeight = 50
    TreeTableView1.SetColumnWidth(0, 180)
    TreeTableView1.SetColumnWidth(1, 60)
    TreeTableView1.SetColumnWidth(3, 180)
    'SubExists("x","TEST")
    IterateOverChildren(TreeTableView1.Root)
    
    TTV_agac.Initialize("TTV_agac")
    TTV_agac.SetSize(300,280)
    TTV_agac.RowHeight=40
    TTV_agac.Root.Initialize("",Array As String("1","2"))
    MainForm.RootPane.AddNode(TTV_agac,0,0,100,280)
    TTV_agac.Root.Children.Initialize
    TTV_agac.Root.Children.AddAll(TreeTableView1.root.Children)
    
End Sub

Sub AddFolder(Parent As TreeTableItem, Folder As String)
    For Each f As String In File.ListFiles(Folder)
        Dim tti As TreeTableItem
        Dim Name As String = f
        Dim Size As String = $"$1.0{File.Size(Folder, f) / 1024} KB"$
        Dim Date As String = $"$DateTime{File.LastModified(Folder, f)}"$
        Dim p As Pane
        p.Initialize("")
        p.LoadLayout("ItemLayout")
        tti.Initialize("tti", Array(Name, Size, Date, p))
        btnItem.Tag = tti
        Parent.Children.Add(tti)
        If File.IsDirectory(Folder, f) Then
            AddFolder(tti, File.Combine(Folder, f))
            tti.Expanded = True
            tti.Image = FolderImage
        End If
    Next
End Sub

Sub btnItem_Action
    Dim b As Button = Sender
    Dim tti As TreeTableItem = b.Tag
    lblSelectedItem.Text = "Clicked on: " & FullNameFromItem(tti)
End Sub


Sub test
    TreeTableView1.PrefWidth=(200)
End Sub


Sub btnListSelected_Click
    TreeTableView1.PrefWidth=(200)
    
End Sub
Sub btnListSelected_Action
    Log("Selected items:")
    IterateOverChildren(TreeTableView1.Root)
End Sub

Sub IterateOverChildren(parent As TreeTableItem)
    For Each tti As TreeTableItem In parent.Children
        Dim p As Pane = tti.GetValue(3)
        Dim chk As CheckBox = p.GetNode(0) 'first node
        If chk.Checked Then
            Log("Selected: " & FullNameFromItem(tti))
        End If
        If tti.Children.Size > 0 Then
            IterateOverChildren(tti)
        End If
    Next
End Sub

Sub FullNameFromItem(tti As TreeTableItem) As String
    Dim sb As StringBuilder
    sb.Initialize
    'combine the first column of this item and its parents
    Do While tti.Root = False
        If sb.Length > 0 Then
            sb.Insert(0, "\")
        End If
        sb.Insert(0, tti.GetValue(0))
        tti = tti.Parent
    Loop
    Return sb.ToString
End Sub

Sub TreeTableView1_SelectedItemChanged (SelectedItem As TreeTableItem)
    'It will not be initialized when the selection is cleared
    If SelectedItem.IsInitialized = False Then Return
    lblSelectedItem.Text = FullNameFromItem(SelectedItem)
End Sub
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Can you zip and post the project? there is too much to rebuild to get it running.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
It's failing because you haven't set any columnnames

If you are only going to print it, you might get away with copying the items, but it would be better to recreate them.
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    MainForm.RootPane.LoadLayout("1")
    FolderImage = fx.LoadImage(File.DirAssets, "Folder.png")
    AddFolder(TreeTableView1.Root, File.DirApp)
    TreeTableView1.RowHeight = 50
    TreeTableView1.SetColumnWidth(0, 180)
    TreeTableView1.SetColumnWidth(1, 60)
    TreeTableView1.SetColumnWidth(3, 180)
    'SubExists("x","TEST")
    IterateOverChildren(TreeTableView1.Root)
    
    TTV_agac.Initialize("TTV_agac")
    TTV_agac.SetColumns(Array As String("Name","Size","Date","Action"))
    TTV_agac.SetSize(500,280)
    TTV_agac.SetColumnWidth(0, 180)
    TTV_agac.SetColumnWidth(1, 60)
    TTV_agac.SetColumnWidth(3, 180)
    TTV_agac.RowHeight=40
    MainForm.RootPane.AddNode(TTV_agac,0,300,500,280)
    AddFolder(TTV_agac.Root, File.DirApp)
    
'    TTV_agac.Root.Children.AddAll(TreeTableView1.root.Children)
'    TTV_agac.SetSize(300,280)
'    TTV_agac.RowHeight=40
'    TTV_agac.Root.Initialize("",Array As String("1","2"))
'    MainForm.RootPane.AddNode(TTV_agac,0,0,100,280)
'    TTV_agac.Root.Children.Initialize
'    TTV_agac.Root.Children.AddAll(TreeTableView1.root.Children)
    
End Sub
 
Upvote 0
Top