Preserving open nodes in AdvancedDataGrid with HierarchicalCollectionView

My dataProvider is an ArrayCollection, which is populated using XML.

var initXML:XML = <items>
   <item id="News" label="News" value_1="unchecked" value_2="unchecked" value_3="checked"/>
   <item id="BBC" label="The Web" value_1="unchecked" value_2="unchecked" value_3="checked">
       <item id="BBC1" label="BBC Homepage" value_1="unchecked" value_2="unchecked" value_3="checked">
      <item id="YouTube" label="YouTube" value_1="unchecked" value_2="unchecked" value_3="checked"/>
      <item id="GoogleMaps" label="Google Maps" value_1="unchecked" value_2="unchecked" value_3="checked"/>
      <item id="MSN" label="MSN" value_1="unchecked" value_2="unchecked" value_3="checked"/>
       </item>
       <item id="Wikipedia" label="Wikipedia" value_1="unchecked" value_2="unchecked" value_3="checked"/>
       <item id="Dilbert" label="Jasper Report" value_1="unchecked" value_2="unchecked" value_3="checked"/>
       <item id="PhD" label="Test Page" value_1="unchecked" value_2="unchecked" value_3="unchecked"/>
   </item>
   <item id="Blogs" label="Jasper Reports" value_1="unchecked" value_2="unchecked" value_3="checked">
       <item id="Blog1" label="Report Invoker" value_1="unchecked" value_2="unchecked" value_3="checked"/>
       <item id="Blog2" label="Dashboard" value_1="unchecked" value_2="unchecked" value_3="checked"/>
       <item id="Blog3" label="Morning Report" value_1="unchecked" value_2="unchecked" value_3="checked"/>
   </item>
    </items>;


public function loadDataResultHandler(newXML:XML):void
{
   dataProvider.removeAll(); // dataProvider is an ArrayCollection
   for each (var s:XML in newXML.item)
      dataProvider.addItem(s);
   dataProvider.refresh();
   advancedDG.validateNow();

   var openNodes:Object;
   if (advancedDG.dataProvider != null)
      openNodes = IHierarchicalCollectionView(advancedDG.dataProvider).openNodes;
   IHierarchicalCollectionView(advancedDG.dataProvider).openNodes = {}; // prevents memory leak

   for each (var openNode:XML in openNodes)
      for each (var item:XML in newXML.descendants("item"))
         if (item.@id[0] == (openNode.@id)[0])
         {
            advancedDG.expandItem(item, true);
            break;
         }
}

Comments