Force updating a Flex Tree control

I was creating a custom control by inheriting from the standard Tree control present in Flex – one wierd issue however was that the control UI was not updating as soon as I changed the values in the data provider.

Turns out, there is a hack for this – this stackoverflow question (and the corresponding answer) saved my day!

For brevity, the solution is to use a method like this to bind the data again and return the tree to the state it was –

private function forceRedraw(tree:Tree, dataProvider:Object):void
    var scrollPosition:Number = tree.verticalScrollPosition;
    var openItems:Object = tree.openItems;
    tree.dataProvider = dataProvider;
    tree.openItems = openItems;
    tree.verticalScrollPosition = scrollPosition;

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see