views:

652

answers:

1

Hi All I have a problem with an AdvancedDataGrid; i want the fields Actual and Estimate to change with the timer function but it doesn't work. It works only by refreshing all the adg with the collapse of the tree structure. I want that if the tree is "exploded" only actual and estimate fields refresh. Sorry for my uncorrect english. Here's the code

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication initialize="init();" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 <mx:Script>
  <![CDATA[
   import mx.utils.ArrayUtil;
   import mx.collections.*;
   import flash.utils.Timer;
   import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
   [Bindable]
   public var randomNumber:Number = new Number
   public function randomValues():Number
   {
   randomNumber=Math.random()*100
   randomNumber*=100
   randomNumber=Math.round(randomNumber)
   randomNumber/=100
   trace(randomNumber)
   return randomNumber
   } 
   public var timer:Timer = new Timer(20);
      public function timing():void{
      timer.addEventListener(TimerEvent.TIMER,function(event:Event):void{randomValues()});
      }
      [Bindable]
      public var dpFlat:ArrayCollection = new ArrayCollection;
      public function dpCollection():ArrayCollection
      {
      dpFlat= new ArrayCollection([
      {Continente:"Europa", Paese:"Italia", Actual:randomValues(), Estimate:randomValues()},
      {Continente:"Europa", Paese:"Germania", Actual:randomValues(), Estimate:randomValues()}
       ]);
      return dpFlat;
      }

      public function init():void{
      dpCollection()
      randomValues() 
      }


  ]]>
  </mx:Script>
  <mx:AdvancedDataGrid horizontalScrollPolicy="on" columnWidth="100" resizableColumns="false" id="myADG" width="469" height="223" color="0x323232" initialize="gc.refresh();">        
             <mx:dataProvider>
                <mx:GroupingCollection id="gc" source="{dpCollection()}">
                    <mx:grouping>
                        <mx:Grouping>
                            <mx:GroupingField name="Continente"/>
                            <mx:GroupingField name="Paese"/>
                        </mx:Grouping>
                    </mx:grouping>
                </mx:GroupingCollection>
             </mx:dataProvider>        

            <mx:columns>
                <mx:AdvancedDataGridColumn dataField="Continente"/>
                <mx:AdvancedDataGridColumn dataField="Paese"/>
                <mx:AdvancedDataGridColumn id="act" dataField="Actual"/>
                <mx:AdvancedDataGridColumn id="est" dataField="Estimate"/>


            </mx:columns>
    </mx:AdvancedDataGrid>
 <mx:TextArea text="{randomNumber}" x="477" y="10"/>
 <mx:Button click="timing()" x="10" y="231" label="Start timing function"/>
 <mx:Button click="timer.start()" x="161" y="231" label="Start the time"/>
 <mx:Button click="timer.stop()" x="275" y="231" label="Stop the time"/>
</mx:WindowedApplication>
A: 

You are not changing the dataProvider in the Timer handler. You are just calling the randomValues() method that just returns a number.

Call gc.source = dpCollection(); from the Timer's handler.


Update: Apparently, the IGroupingCollection does not detect changes to a group automatically, so you must call the refresh() method to update the view after setting the group property.

There seem to be a work around to this issue here

Amarghosh
it doesn't work or maybe i can't set the timer's handlercould you please write some line codes?thanks
Franky
see the update.
Amarghosh
it doesn't work... it works only with simple datagrid, the problem is changing only some fields of the advanceddatagrid. Maybe the problem is in the arraycollection because if i refresh the whole arraycollection i have new random values but the hierarchical tree view collapses..
Franky