1 Reply Latest reply on Oct 1, 2007 5:21 AM by chris.huston.t10

    DataGrid and Collections

    SidewinderV2
      Hello, I have a DataGrid with 2 columns, and when the a button is pressed, it is suppose to increment two numbers and update the DataGrid with those numbers. Right now, it does add the two numbers to the grid, but no on the same row. When you click the button the first time it does this:

      ----------------------
      |----0----- |--------|
      ----------------------
      |-----------| --10--|
      ----------------------

      When I really want this:

      ----------------------
      |----0----|---10---|
      ----------------------

      Below is my code, can someone help me?



      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" height="194" width="324">
      <mx:Script>
      <![CDATA[
      import mx.collections.ArrayCollection;
      var i:int = 0;
      var j:int = 10;
      var ac:ArrayCollection = new ArrayCollection();

      private function script():void
      {
      ac.addItem({col1:i});
      ac.addItem({col2:j});
      i++;
      j++;
      list.dataProvider=ac;
      }
      ]]>
      </mx:Script>

      <mx:DataGrid x="10" y="10" id="list">
      <mx:columns>
      <mx:DataGridColumn headerText="Column 1" dataField="col1"/>
      <mx:DataGridColumn headerText="Column 2" dataField="col2"/>
      </mx:columns>
      </mx:DataGrid>
      <mx:Button x="10" y="160" label="Button" click="script()" id="button"/>

      </mx:Application>
        • 1. Re: DataGrid and Collections
          chris.huston.t10 Level 3
          Here is what I would do:

          [Bindable]
          private var ac:ArrayCollection = new ArrayCollection();

          private function script():void
          {
          ac.addItem({col1:i,col2:j});
          i++;
          j++;
          }
          ]]>
          </mx:Script>

          <mx:DataGrid x="10" y="10" id="list" dataProvider="{ac}">
          <mx:columns>
          <mx:DataGridColumn headerText="Column 1" dataField="col1"/>
          <mx:DataGridColumn headerText="Column 2" dataField="col2"/>
          </mx:columns>
          </mx:DataGrid>

          Vygo