AX – D365FO – Auto collapse whole tree in FormTreeControl

If you have a Tree control on your form and want to collapse the whole tree with all items and subitems at once, you can use the following static method:

SysFormTreeControl::collapseTree(FormTreeControl _formTreeControl, TreeItemIdx _treeItemIdx, int _toLevel = 0,int _level = 0 )

For example to expand the whole tree from the root item to the inner most item:

SysFormTreeControl:: collapseTree (TreeCtrl, TreeCtrl.getRoot());
Or only from the current selection item down the tree:

SysFormTreeControl:: collapseTree (TreeCtrl, TreeCtrl.getSelection());

Leave a comment