views:

6040

answers:

4

Does anyone know how to programmatically expand the nodes of an AdvancedDataGrid tree column in Flex? If I was using a tree I would use something like this:

dataGrid.expandItem(treeNodeObject, true);

But I don't seem to have access to this property in the AdvancedDataGrid.

Thanks for your help!

+1  A: 

AdvancedDataGrid has an expandItem() method too:

http://livedocs.adobe.com/flex/3/langref/mx/controls/AdvancedDataGrid.html#expandItem()

Eric Belair
+2  A: 

Copy the sample found at the aforementioned url and call this function: private function openMe():void { var obj:Object = gc.getRoot(); var temp:Object = ListCollectionView(obj).getItemAt(0); myADG.expandItem(temp,true); }

slukse
+1  A: 

You could also open nodes by iterating through the dataProvider using a cursor. Here is how I open all nodes at a specified level:

    private var dataCursor:IHierarchicalCollectionViewCursor;

    override public function set dataProvider(value:Object):void
    {
        super.dataProvider = value;

        /* The dataProvider property has not been updated at this point, so call 
            commitProperties() so that the HierarchicalData value is available. */
        super.commitProperties();

        if (dataProvider is HierarchicalCollectionView)
            dataCursor = dataProvider.createCursor();
    }

    public function setOpenNodes(numLevels:int = 1):void
    {
        dataCursor.seek(CursorBookmark.FIRST);

        while (!dataCursor.afterLast)
        {
            if (dataCursor.currentDepth < numLevels)
                dataProvider.openNode(dataCursor.current);
            else
                dataProvider.closeNode(dataCursor.current);

            dataCursor.moveNext();
        }

        dataCursor.seek(CursorBookmark.FIRST, verticalScrollPosition);

        // Refresh the data provider to properly display the newly opened nodes
        dataProvider.refresh();
    }
Eric Belair
A: 

Can someone explain the significance of the 2nd last line?

dataCursor.seek(CursorBookmark.FIRST, verticalScrollPosition);

Does this tell the view (ADG) to scroll?

tntomek