3 Replies Latest reply on Aug 28, 2006 10:39 AM by seth_hodgson

    Datagrid Not Populating

    hhr_jb Level 1
      Hello,

      Does anyone know why my datagrid is not populating? It runs with no error, but no data is coming up.

      Thanks,
      Jimmy

      Here's the code to the not working version

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="vertical">

      <mx:Script>
      <![CDATA[
      import mx.rpc.events.ResultEvent;
      import mx.collections.ArrayCollection;

      [Bindable]
      private var myData:ArrayCollection;

      private function resultHandler(event:ResultEvent):void{
      myData = event.result as ArrayCollection;
      }
      ]]>
      </mx:Script>

      <mx:WebService id="myService"
      wsdl=" http://www.hawaiihotels.com/WSTest/Inventory.cfc?wsdl"
      load="myService.getInventory();"
      result="resultHandler(event)"/>

      <mx:DataGrid dataProvider="{myData}"/>
      </mx:Application>
        • 1. Re: Datagrid Not Populating
          seth_hodgson
          Hi Jimmy,

          Your event.result contains an Array. The 'as' operator attempts to cast to the type you've specified (ArrayCollection) and if it can't returns null. So your app was binding null to the grid's dataProvider property. You could either do:

          myData = new ArrayCollection(event.result as Array);

          or change myData to type Array and do:

          myData = event.result as Array;

          Best,
          Seth
          • 2. Re: Datagrid Not Populating
            sanclementetech Level 1
            I thought it was suppose to be

            myData = event.lastResult;

            is this only for java stuff?
            • 3. Re: Datagrid Not Populating
              seth_hodgson Level 1
              The list-based classes (including DataGrid) do some massaging in the setter for dataProvider. If the assigned value is an Array it is wrapped automatically in an ArrayCollection. If it's already a ListCollectionView (ArrayCollection or XMLListCollection) it's used as is.

              If the server returns data that's unpacked as an Array or ArrayCollection either would be directly assignable to the dataProvider property so a direct binding expression to a WebService operation's lastResult would just work. However, if having the local variable is useful it needs to be the proper type to store the result.

              Best,
              Seth