# List Tree - How to Contract All Branches

**URL:** <https://clarionhub.com/t/list-tree-how-to-contract-all-branches/6480>\
**Category:** uncategorized\
**Created:** [August 11, 2023, 1:02pm UTC](https://clarionhub.com/t/list-tree-how-to-contract-all-branches/6480 "2023-08-11T13:02:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![edo1403](https://clarionhub.com/letter_avatar_proxy/v4/letter/e/46a35a/32.png) [@edo1403](https://clarionhub.com/u/edo1403)\
**Post date:** [August 11, 2023, 1:02pm UTC](https://clarionhub.com/t/list-tree-how-to-contract-all-branches/6480/1 "2023-08-11T13:02:10Z")

</div>

How can I contract all nodes from picture. I want to see only root nodes (1, 2 3 4) ?  
May be formatting with ?List{PROP:format}  
Clarion 6.3

 ![1](https://clarionhub-uploads.s3.eu-north-1.amazonaws.com/original/2X/e/e847be1f0f9c3bc7a66668f177e24205f071b729.png)

---

<div class="post-metadata">

**Author:** ![Rick\_UpperPark](https://clarionhub.com/user_avatar/clarionhub.com/rick_upperpark/32/346_2.png) [@Rick\_UpperPark](https://clarionhub.com/u/Rick_UpperPark)\
**Post date:** [August 11, 2023, 1:40pm UTC](https://clarionhub.com/t/list-tree-how-to-contract-all-branches/6480/2 "2023-08-11T13:40:41Z")

</div>

This assumes your LevelField is 1 based.

```auto
loop curRow = 1 to records(TreeQueue)
  get(TreeQueue, curRow)
  if TreeQueue.LevelField > 1 
    TreeQueue.LevelField *= -1 ! make negative to close branch
    put(TreeQueue)
  end
end

```

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [August 13, 2023, 9:26pm UTC](https://clarionhub.com/t/list-tree-how-to-contract-all-branches/6480/3 "2023-08-13T21:26:15Z")

</div>

> [@Rick\_UpperPark](#):
>
> ```auto
> if TreeQueue.LevelField > 1 
> TreeQueue.LevelField *= -1 ! make negative to close branch
> 
> ```

One Cosmetic flaw with that code is it makes ALL Branches Negative so ALL Contracted. The flaw is it will show a Contracted Box ( a Plus `[+]` ) on Branches that do not have lower levels. When the User clicks on the `[+]` nothing happens because there are no lower records. Like your first row “1” has nothing on level 2.

To prevent that only Contract branches that have lower levels, i.e. leave them as positive level numbers.

I coded that like below by LOOP in the Reverse “BY -1” to allow saving the previous lower level number.

```auto
TreeExpandContract (SomeQ, SomeQ:Level, True) !Contract Tree
TreeExpandContract (SomeQ, SomeQ:Level, False) !Expand Tree

TreeExpandContract PROCEDURE(QUEUE TreeQ, *LONG Level, BYTE Contract=0)
Prv LONG !Keep Previous Record Level
    CODE
    LOOP X=RECORDS(TreeQ) TO 1 BY -1 !Reverse Loop Bottom to Top
        GET(TreeQ,X) 
        Level=ABS(Level) 
        IF Level=1 THEN
           IF Contract THEN 
              IF Prv=2 THEN Level=-1.
           END
           PUT(TreeQ)
        END
        Prv=Level
    END

```

Looking at the above code I think if it only works for a 2 Level Tree, which is what I had in the program I pulled it from. It also does not have a Root at Level 1. So you’ll need to adjust the code. Or maybe that does work for you as you only want to Contract Level 1.

 ![image](https://clarionhub-uploads.s3.eu-north-1.amazonaws.com/original/2X/b/bf084d4beb11145fe55e977c10642afc349dcd99.png)

---

<div class="post-metadata">

**Author:** ![edo1403](https://clarionhub.com/letter_avatar_proxy/v4/letter/e/46a35a/32.png) [@edo1403](https://clarionhub.com/u/edo1403)\
**Post date:** [August 15, 2023, 6:37am UTC](https://clarionhub.com/t/list-tree-how-to-contract-all-branches/6480/4 "2023-08-15T06:37:50Z")

</div>

It works . Thank you both.

---

<div class="post-metadata">

**Author:** ![xxetfxx](https://clarionhub.com/user_avatar/clarionhub.com/xxetfxx/32/5215_2.png) [@xxetfxx](https://clarionhub.com/u/xxetfxx)\
**Post date:** [January 11, 2026, 3:04pm UTC](https://clarionhub.com/t/list-tree-how-to-contract-all-branches/6480/5 "2026-01-11T15:04:29Z")

</div>

Hi Carl,  
Is it possible to change expand/contract boxes icon to a custom icon using this handcoded tree list?

Thanks.

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [January 12, 2026, 12:00pm UTC](https://clarionhub.com/t/list-tree-how-to-contract-all-branches/6480/6 "2026-01-12T12:00:49Z")

</div>

I don’t recall a way to do it. I’d suggest looking at the Relation Tree template as it allows levels with different icons.

I would guess it could be done by turning off the Tree Boxes, then use the List Column Icon to show your desired Box Icon.

You would have to manage changing the Icon based on Event Expand and Contract. Plus not show an Expand Icon if they are no children.

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [January 12, 2026, 3:43pm UTC](https://clarionhub.com/t/list-tree-how-to-contract-all-branches/6480/7 "2026-01-12T15:43:34Z")

</div>

Been a while since I’ve done a tree.

Maybe toggling PROPList:TreeBoxes would allow you to shut off the tree boxes, then you could use the appropriate iconlist number to set expanded/contracted icons?

---

<div class="post-metadata">

**Author:** ![seanh](https://clarionhub.com/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@seanh](https://clarionhub.com/u/seanh)\
**Post date:** [January 13, 2026, 1:06am UTC](https://clarionhub.com/t/list-tree-how-to-contract-all-branches/6480/8 "2026-01-13T01:06:39Z")

</div>

I’m pretty sure you need to go through the queue and set the level byte to -ve.  
I don’t have clarion open atm to check. but I’m pretty sure -ve = contract, +ve = expand
