2 Replies Latest reply on Jan 1, 2010 9:56 PM by kkc_mca

    DataGrid will not refresh

    lee704 Level 1

      I have a DataGrid in a component.  The dataProvider for the DataGrid is an ArrayCollection in my main application.  I use the ArrayCollection in several components.

       

      My problem is, after the component with the DataGrid is created, I cannot refreh the data in the DataGrid.  For example, if I change a record in the a DataGrid tied to a the ArrayCollection on the main application, the change is not displayed in any other DataGrids that use the ArrayCollection.

       

      I have tried several methods to get the DataGrids to refresh from the simple dataProvider.refresh() to more complex methods with the same result.  To get the data in the DataGrids to refresh, I have to close the application and re-open it.

       

      Is there a way to reresh my DataGrids after they have been created?  Can I "uncreate" the DtaGrid and recreate it so that it gets the updated data?

       

      Thanks!

      Lee

        • 1. Re: DataGrid will not refresh
          alex-86 Level 1

          if the array is changing when you udpate it, why dont you try to set a new dataprovider of the same array.

          1 person found this helpful
          • 2. Re: DataGrid will not refresh
            kkc_mca Level 2

            Use Data Binding concepts to refresh the DataGrid.

            The main use of Data Binding is when the data(Array collection) is changed it automatically reflects on the data grid, no need to call refresh etc.,

            Here Is the example

             

            <?xml version="1.0"?>
            <!-- dpcontrols/DataGridPassData.mxml -->
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
               initialize="initData()">
               <mx:Script>
               <![CDATA[
                  import mx.collections.*;
                  private var DGArray:Array = [
                     {Artist:'Pavement', Album:'Slanted and Enchanted', Price:11.99},
                     {Artist:'Pavement', Album:'Brighten the Corners', Price:11.99}];
                     
                  [Bindable]
                  public var initDG:ArrayCollection;
                  //Initialize initDG ArrayCollection variable from the Array.
                  //You can use this technique to convert an HTTPService, 
                  //WebService, or RemoteObject result to ArrayCollection.
                  public function initData():void {
                     initDG=new ArrayCollection(DGArray);
                  }
               ]]>
               </mx:Script>
            
               <mx:DataGrid id="myGrid" width="350" height="200" 
                  dataProvider="{initDG}" >  <!-- using data binding -->
                  <mx:columns>
                     <mx:DataGridColumn dataField="Album" />
                     <mx:DataGridColumn dataField="Price" />
                  </mx:columns> 
               </mx:DataGrid>
            </mx:Application>
            
            for reference http://livedocs.adobe.com/flex/3/html/help.html?content=dpcontrols_6.html
            If this post answers your question or helps. Please mark it as such .

            1 person found this helpful