3 Replies Latest reply on Nov 29, 2007 11:54 PM by shapeshifta78

    [Solved] Get Data from DataGrid?

      Hi there,

      I have two grids, drag and drop enabled. One is my item list and the other my shopping cart.
      After dropping items to the cart, I'd like to fetch the data from the cart and calculate the sum of all prices as well as send the list by mail. I have a working form for sending by mail, but I can't figure out how to get the data.
      Someone told me I could use the dataprovider...
      I'm new to flex, can someone help me out with a bit of code or point me to an example anywhere? Sad

      Regards, shape
        • 1. Re: Get Data from DataGrid?
          Best practice for using data aware controls (like grids ).
          declare the data provider lists in variables of application. Be sure to make them bindable
          [Bindable] private var grid1Data:ArrayCollection;
          [Bindable] private var grid2Data:ArrayCollection;

          Either in the mxml declaration or in a method assign your
          collections to the grids as their dataprovider
          <mx:DataGrid id="grid1" dataprovider="{grid1Data} "...

          (Note the braces are important)

          or in ActionScript
          grid1.dataProvider = grid1Data;

          Now because of databinding any changes in the collection will be
          refected in the grid, and any changes to the grid will be reflected in the underlying collection.

          So in whatever you use fill the collection with your data.

          So after you drag and drop operation, just iterate the underlying collection
          and do whatever:

          for each( var o:Object in grid1Data)
          • 2. Re: Get Data from DataGrid?
            shapeshifta78 Level 1
            Thanx a lot!
            Will definitely try that!

            • 3. Re: Get Data from DataGrid?
              shapeshifta78 Level 1
              Worked like a charm, thanx again!