Wednesday, January 14, 2009

Expand Flex tree by clicking row

This is cool, useful and easy. It allows the user to opne a tree branch by clicking anywhere in the parent row (not just the arrow icon):

import mx.events.ListEvent;

private function tree_itemClick(evt:ListEvent):void {
var item:Object = Tree(evt.currentTarget).selectedItem;
if (mytree.dataDescriptor.isBranch(item)) {
mytree.expandItem(item, !mytree.isItemOpen(item), true);
}
}

...
itemClick="tree_itemClick(event);" />

1 comment:

JLR said...

Thanks for the snippet; works like a charm! I tweaked it a bit, declaring "mytree" locally within the function.

private function tree_itemClick(evt:ListEvent):void {
var mytree:Tree = Tree(evt.currentTarget);
var item:Object = mytree.selectedItem;

if (mytree.dataDescriptor.isBranch(item)) {
mytree.expandItem(item, !mytree.isItemOpen(item), true);
}
}