5 Replies Latest reply on Oct 3, 2006 9:40 AM by ClownBootz

    Dynamically refresh a Tree

      Hi Everybody,

      I need to get Tree nodes refreshed based on some criteria. The criteria will be based on a combobox or PopupMenuButton change event. To achieve the same, I am using a Tree control, which is being populated by an XMLListCollection. The XMLListcollection has a filterFunction that filters the tree nodes that will be displayed. The criteria for the filterFunction depends on a ComboBox selection.

      The filterFunction for the XMLListCollection is called during the Combo change event but the tree data is not refreshed and doesnot display the desired filtered result.
      I have tried doing this for a arraycollection with a datagrid and it works fine but doesnot work for a tree. How can we refresh the tree data. Below are the code snippet used to perform the Tree filter which is not working and not throwing any error as well.

      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="vertical" creationComplete="SetFilter();"
      creationPolicy="all" >
      import mx.controls.Alert;
      import flash.events.Event;

      private function SetFilter():void{
      xlc.filterFunction = treeFilter;

      private function treeFilter(item:Object):Boolean{
      var blResult:Boolean = false;
      var csProject:String = item.@label.toString();
      // mx.controls.Alert.show(csProject + " .. " + cmbTree.selectedLabel.toString());
      if(csProject.indexOf(cmbTree.selectedLabel.toString()) != -1){
      blResult = true;
      return blResult;
      <mx:XML id="xmldata" source="data/treedata.xml"/>
      <mx:XMLListCollection id="xlc"
      source="{xmldata.node}" filterFunction="treeFilter"/>

      <mx:Tree id="trTest" dataProvider="{xlc}"
      labelField="@label" showRoot="false">
      <mx:ComboBox id="cmbTree" change="xlc.refresh()">
      <mx:Object label="By Licensee, Project" data="By Licensee, Project"/>
      <mx:Object label="By Licensee, Project, File Type" data="By Licensee, Project, File Type"/>
      <mx:Object label="By Licensee, Date" data="By Licensee, Date"/>
      <mx:Object label="By Licensee, Date, Project" data="By Licensee, Date, Project"/>

      treedata.xml file has the following data that is displayed as tree nodes.
      <node label="By Licensee, Project">
      <node label="Abc">
      <node label="Mugs"/>
      <node label="Test" />
      <node label="By Licensee, Project, File Type">
      <node label="Abc123">
      <node label="Mugs1"/>
      <node label="Test1" />
      <node label="By Licensee, Date">
      <node label="Abc456">
      <node label="Mugs2"/>
      <node label="Test2" />
      <node label="By Licensee, Date, Project">
      <node label="Abc567">
      <node label="Mugs3"/>
      <node label="Test3" />

      Please advise and suggest on where I am going wrong or if there is any other better way to perform the desired result.