Preventing branches from being selected in a Flex Tree control

The following example shows you how you can prevent users from selecting the branch (folder) items in a Tree control in Flex by listening for the itemClick event and using the Tree class’s dataDescriptor.isBranch() method to determine whether the currently selected item is a branch, and if so, deselect the item.

Full code after the jump.


<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<mx:Application xmlns:mx=""


            private function tree_itemClick(evt:ListEvent):void {
                var item:Object = evt.currentTarget.selectedItem
                if (tree.dataDescriptor.isBranch(item)) {
                    tree.selectedItem = null;

    <mx:XML id="dp">
            <node label="Parent 1">
                <node label="Child 1" />
                <node label="Child 2">
                    <node label="Grandchild 1" />
                    <node label="Grandchild 2" />
                <node label="Child 3" />
                <node label="Child 4" />

    <mx:Tree id="tree"
            itemClick="tree_itemClick(event);" />


View source is enabled in the following example.

For more information on disabling list selection in the List/Tree/ComboBox controls, see Alex Harui’s excellent blog entry, “Disabling List Selection”.

For another example, see “Preventing specific items from being selected in a Flex Tree control”.

4 thoughts on “Preventing branches from being selected in a Flex Tree control

  1. However, nothing prevents the user from selecting the item above and using the down arrow key to select the branch.

  2. @Glen … indeed … and I cannot find a way to disable the disclosure button. The TreeItemRenderer assigns a Mouse DOWN event to it but the listener function is private so I can’t override.

Comments are closed.