1 Reply Latest reply on Sep 28, 2010 9:07 AM by rootsounds

    Datagrid, with checkbox to copy data


      Hello all.


      I am trying to create a datagrid component, that adds a checkbox into the last column of a table.  The checkbox when clicked should then copy all the data for that row, and save it into a tempory array, so i can use it later in the application.


      My code is as follows


      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                  import mx.events.IndexChangedEvent;
                  import mx.collections.ArrayCollection;
                  import mx.controls.Alert;
                  private var ac:ArrayCollection=new ArrayCollection([
                      {Name: "John", Score:"25", rating:"3", sel: false},
                      {Name: "Joe", Score:"45", rating:"5", sel: false},
                      {Name: "Jill", Score:"35", rating:"2", sel: false}])
          <mx:DataGrid id="dg"
                       dataProvider="{ac}" x="10" y="10" width="596" height="356">
                  <mx:DataGridColumn headerText="Name" dataField="Name"/>
                  <mx:DataGridColumn headerText="Score" dataField="Score" width="50"/>
                  <mx:DataGridColumn headerText="Rating" dataField="rating" itemRenderer="rate" width="100"/>
                  <mx:DataGridColumn headerText="Select" id="col2" editorDataField="selected" rendererIsEditor="true" dataField="data.sel" width="50">
                                  <mx:CheckBox selected="{data.sel}" change="data.sel=selected" paddingLeft="20">



      Basically the checkbox in the last column needs to be able to when changed to selected==true, copy all the data for that row, the Name, Score and rating, and save it into an array so tha ti can use it later.


      Thanks in advance