0 Replies Latest reply on Mar 2, 2010 9:02 AM by Sherwette.Mansour

    Populate a datagrid

    Sherwette.Mansour

      Hi,

       

      I wanted to populate datagrid 2 with the information collected from a selected item in datagrid 1. When i write the dataprovider shoppingCart.dataProvider = itemsCartID; it writes it in all columns. I want it to populate in just one column. So that it will be written in the id column in the shopping cart datagrid.

       

      I attached the code. Please help me in this if anyone can.

      Thanks

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

      >


      <mx:Script>

      <![CDATA[

       

      import mx.controls.*;

      import mx.events.*;

      import mx.collections.ArrayCollection;

       

      public var itemsCartID:ArrayCollection;

      public var itemsCartURL:ArrayCollection;

       

      public function addtocartSelected(id:String, url:String):void{

       

          itemsCartID= new ArrayCollection();

          itemsCartID.addItem(id);

      //itemsCartURL= new ArrayCollection([url]);

      shoppingCart.dataProvider = itemsCartID;

      //shoppingCart.dataProvider = itemsCartURL;

       

      }

      ]]>

      </mx:Script>


      <mx:XML id="games" source="data.xml"/>


      <mx:Panel width="1200" height="610" layout="absolute" title="Online Store">

          <mx:Label horizontalCenter="0" y="1" text="Store"

             fontSize="16" fontWeight="bold"/>

          <mx:DataGrid id="dgPeeps" x="0" y="25" width="510" height="260" selectedIndex="0" dataProvider="{games.image}">

            <mx:columns>

              <mx:DataGridColumn headerText="Image ID" width="75">

              <mx:itemRenderer>

          <mx:Component>

            <mx:VBox verticalGap="2">

              <mx:Label text="{data.id}" />       

            </mx:VBox>

          </mx:Component>

        </mx:itemRenderer>

              </mx:DataGridColumn>

              <mx:DataGridColumn headerText="Image URL" width="80">

              <mx:itemRenderer>

          <mx:Component>

            <mx:VBox verticalGap="2">

              <mx:Label text="{data.imageURL}" />       

            </mx:VBox>

          </mx:Component>

        </mx:itemRenderer>

              </mx:DataGridColumn>

              <mx:DataGridColumn headerText="Image">

              <mx:itemRenderer>

          <mx:Component>

            <mx:VBox verticalGap="2">

              <mx:Image source="assets/{data.imageURL}" width="100" height="100"

         scaleX=".25" scaleY=".25"/>       

            </mx:VBox>

          </mx:Component>

        </mx:itemRenderer>

              </mx:DataGridColumn>

            </mx:columns>

          </mx:DataGrid>

         

          <mx:Canvas>

          <mx:Image x="10" y="338" width="300" height="240" id="imgGameScreen"

          source="assets/{dgPeeps.selectedItem.imageURL}" visible="true"/>

          <mx:Label x="10" y="293" fontWeight="bold" fontSize="13" id="lblGameName"/>

          <mx:Label x="318" y="318" text="ID:"/>

          <mx:Label x="318" y="335" id="lblID" text="{dgPeeps.selectedItem.id}"/>

          <mx:Label x="318" y="361" text="URL:"/>

          <mx:Label x="318" y="378" id="lblURL" text="{dgPeeps.selectedItem.imageURL}"/>

          <mx:Button x="318" y="400" id="addtocart" label="Add to Cart" click="addtocartSelected(dgPeeps.selectedItem.id,

          dgPeeps.selectedItem.imageURL)"/>

          </mx:Canvas>

         

          <mx:VBox x="562" y="33" height="512" width="431" backgroundColor="#D91E1E">

      <mx:Label text="Your Shopping Cart" fontWeight="bold"/>

      <mx:DataGrid id="shoppingCart"  >

      <mx:columns>

      <mx:DataGridColumn headerText="id" dataField="id"/>

      <mx:DataGridColumn headerText="price" dataField="imageURL"/>

      <mx:DataGridColumn headerText="quantity" dataField="col3"/>

      </mx:columns>

      </mx:DataGrid>

      </mx:VBox>

        </mx:Panel>

       

       

      </mx:Application>