2 Replies Latest reply on Oct 14, 2006 9:26 AM by UBICX

    DataGrid

    babo_ya Level 3
      Hi,

      I created a DataGrid object,
      <mx:DataGrid width="497" editable="true" height="185" x="0" y="1" id="dg" itemClick="DataGridItemClick(event);">
      <mx:columns>
      <mx:Array>
      <mx:DataGridColumn dataField="quantity" headerText="Quantity" editable="true">
      </mx:Array>
      </mx:columns>


      </mx:DataGrid>

      ... And I made this datagrid as editable = true... So my question is how do I go thru each row and find out what the value is?
      I know in Flash there is a method called 'getItemAt(index);" which returns data I need.

      Thanks for your help.
        • 1. Re: DataGrid
          peterent Level 2
          The DataGrid is just a view of your data in a collection. When you want to access the data, do it from the collection - the dataProvider property of your DataGrid. For example:

          [Bindable] private var dp:ArrayCollection = new ArrayCollection( [ {col1:"Test", col2:1203, col3:"Apples"}, ... ] );
          <mx:DataGrid dataProvider="{dp}" ... >

          When you edit the DataGrid on the screen, those changes are stored back into the dataProvider, dp in this case. When you want to get to the data, use dp:

          for(var i:Number=0; i < dp.length; i++) {
          var item:Object = dp.getItemAt(i);
          // do something with item
          }
          • 2. Re: DataGrid
            UBICX
            I have a solution to this :
            i use a arraycollection to list data of the datagrid.
            i use dataprovider directly from HTTPService:
            <mx:DataGrid dataProvider="{sourcetemps.lastResult.tempss.temps}"
            because when i use this :
            tempsCol = event.result.tempss.temps as ArrayCollection;
            HTTPService return only 1 item i have nothing in arraycollection

            [Bindable]
            private var tempsCol:ArrayCollection;

            private function bsResultHandler(event:ResultEvent):void
            {
            tempsCol = ArrayCollection(temps.dataProvider);
            Inbligne = 0;
            Itemps = 0;
            for each (var tempsColValue in tempsCol) {
            Inbligne = Inbligne + 1;
            Itemps = Itemps + tempsColValue.leTemps
            }
            lnbligne.text = Inbligne.toString();
            ltemps.text = Itemps.toString();
            CursorManager.removeBusyCursor();
            }