B4J Question CheckBoxTreeItem as child set and read

Iatros

Member
Licensed User
I try to read all checked nodes. It works, if I have only root nodes. But now I try to work with root and child nodes. But I only can set and read the childs as TreeItem instead of CheckBoxTreeItem. Perhaps someone can halp ?

B4X:
        If bFill = True Then
    objTreeQKoerper.SetCheckBoxesMode

            If sZW(2) = "P" Then
                Dim cti As CheckboxTreeItem
                cti.Initialize("ti", sZW(0))
                objTreeQKoerper.Root.Children.Add(cti)
            Else
                Dim ti As TreeItem ' CheckBoxTreeItem not possible
                ti.Initialize("ti", sZW(0))
                cti.Children.Add(ti)
            End If
        End If

B4X:
    For Each tn As CheckboxTreeItem In objTreeQKoerper.Root.Children
        Log(tn.Text)
        For i = 0 To tn.Children.Size - 1
            Dim tc As TreeItem ' CheckBoxTreeItem not possible
            tc = tn.Children.Get(i)
            Log(tc.Text)
        Next
    Next
 

stevel05

Expert
Licensed User
Longtime User
Your logic is not quite right. Try this:

B4X:
 For Each O As Object In objTreeQKoerper.Root.Children
       If O Is CheckBoxTreeItem Then
            Dim tc As CheckBoxTreeItem = O
            Log(tc.Text)
        Else
             Dim ti As TreeItem = O
            Log(ti.Text)
        End If
        Next
    Next
 
Upvote 0

Iatros

Member
Licensed User
Thank you. But it displays only the root nodes. A have to set and read the checked property inside a loop. I think the childs only hava a checkbox because the whole tree is set to SetCheckBoxesMode. But on creating the childs I can't define it as checkboxnodes.
 

Attachments

  • b4jtree.png
    b4jtree.png
    15.2 KB · Views: 124
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Can you upload an example project. otherwise I'll have to build one.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Looking a little deeper it appears you are correct.

To show the checkboxes the treeview needs to be set to checkbox mode and can contain only checkbox items.
 
Upvote 0

Iatros

Member
Licensed User
Oh, I just made a test project. Not needed I see.
Thank you very much. I will switch to TreeTableView.
 
Upvote 0

Iatros

Member
Licensed User
Only for info - Before I look after TreeTableView I did it on my own way (your "For Each O As Object" was the key). So I have the functionality I need.


B4X:
    Dim iEntries As Int = 0
    Dim iResonanzen As Int = 0
  
    For Each O As Object In objTreeQKoerper.Root.Children
        iEntries = iEntries + 1
        Dim ti As TreeItem = O
        ti.Image = treeblank .GetImage
        If fCheckEntry = True Then
            ti.Image = treeres .GetImage
            iResonanzen = iResonanzen + 1
        End If

        Dim ti2 As TreeItem
        ti2 = ti
        For i = 0 To ti2.Children.Size - 1
            iEntries = iEntries + 1
            Dim trItemChild As TreeItem
            trItemChild = ti2.Children.Get(i)
            trItemChild.Image = treeblank .GetImage
            If fCheckEntry = True Then
                trItemChild.Image = treeres .GetImage
                iResonanzen = iResonanzen + 1
            End If
        Next
    Next 
    lblResonanzenQKoerper.Text = iResonanzen & " / " & iEntries
 
Last edited:
Upvote 0
Top