2009-11-27 74 views
0

我有一個AdvancedDataGrid的問題;我希望字段實際和估計改變與定時器功能,但它不起作用。它只能通過樹形結構的崩潰刷新所有的adg。我想如果樹被「爆炸」,只有實際和估計字段刷新。對不起,我的英文不正確。 下面的代碼AdvancedDataGrid數據字段刷新

<?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> 

回答

0

你是不是在Timer處理程序改變dataProvider。您只是調用返回數字的randomValues()方法。

從定時器的處理程序調用gc.source = dpCollection();


更新:Apparently,該IGroupingCollection沒有自動檢測更改一組,所以你必須調用refresh()方法來設置該組屬性後更新視圖。

似乎有圍繞一個工作,這個問題here

+0

它不工作或也許我不能設置定時器的處理程序 能否請你寫一些代碼行? 謝謝 – Franky 2009-11-27 16:31:40

+0

查看更新。 – Amarghosh 2009-11-27 17:47:42

+0

它不起作用...它只適用於簡單的數據網格,問題只改變了advanceddatagrid的一些字段。也許問題是在arraycollection,因爲如果我刷新整個arraycollection我有新的隨機值,但分層樹視圖崩潰.. – Franky 2009-11-30 09:59:06