tags:

views:

37

answers:

1

So, I have a custom Tree in which some nodes need to be marked as disabled. That is, they should be grayed out, and they should never be able to be selected. I've been able to prevent a user from selecting these disabled nodes by clicking on them pretty easily. However, I ran into the issue that if you have a child of the disabled node selected, and then collapse the disabled node, flex automatically selects the disabled node.

I tried to overcome this by overriding the expandItem method as such:

        // Make sure nodes user doesn't have access to aren't accidentally selected when collapsing a branch
    override public function expandItem(item:Object, open:Boolean, animate:Boolean = false, dispatchEvent:Boolean =
        false, cause:Event = null):void
    {
        super.expandItem(item, open, animate, dispatchEvent, cause);

        if (!open && !(item as ScorecardTreeNode).enabled)
            selectedItem = null;
    }

All of the items in the tree are of this ScorecardTreeNode type, which has an "enabled" property that is set based on whether or not the user should have access to the node.

This works pretty well, but I've found a peculiar exception that I just can't figure out. If I have a hierarchy such as:

Root > Disabled node > Child of disabled node

And I 1) select the "Child of disabled node" then 2) collapse the root (so now the root is selected), then 3) expand the root, 4) select "Child of disabled node" again, and then 5) collapse the "Disabled node", the "Disabled node" will be selected, even though stepping through the debugger shows the "selectedItem = null" line is still being hit.

Any ideas as to why this is happening?

A: 

Try setting selectedItem to -1 instead of null.

JonnyP
Unfortunately this still produces the same result
Josh